<pre><code>compass=[student.strip() for student in open("compassfeb8.txt",'U')]
roster=[student.strip() for student in open("feb4py.txt",'U')]
dropped=False
for name in compass:
if name not in roster:
print name
dropped=True
if not dropped:
print "Hooray! Nobody dropped."
</code></pre>
<p>此代码无效。但是,以下代码不适用:</p>
<pre><code>roster1=[student.strip() for student in open("jan24py.txt",'U')]
roster2=[student.strip() for student in open("feb4py.txt",'U')]
new_students=False
for name in roster2:
if name not in roster1:
print name
new_students=True
if not new_students:
print "There were no new students."
</code></pre>
<p>对于第一个代码块,我试图找出哪些学生仍然是我们班级网站的用户,但不在学校的正式花名册上,这样我们就可以把他们从班级网站上删除。你知道吗</p>
<p>第二个代码块检查是否有新学生。你知道吗</p>
<p>这是相当尴尬,但我不知道如何缩进时,粘贴我的代码。(我将在接下来的几周里学习HTML。)但是,我相信我所有的缩进都是正确的。你知道吗</p>