<p>我目前正在为我的编程课程简介编写一个程序。要求是让用户输入名人名单,将他们添加到名单中,打印出输入的名人数量,然后打印出输入的名人名单。我必须使用一个循环,所以我使用了while循环;但是当用户将<code>Done</code>输入到names输入字段时,我不能使它结束。在</p>
<p>下面是代码,以及我尝试使用if-else语句控制循环。在</p>
<pre><code>def main():
celebs = []
again = 'y'
while again == 'y':
name = input('Enter a name: ')
if name == 'Done':
again == 'n'
else:
again == 'y'
celebs.append(name)
print('You entered ',len(celebs), 'celebrities to the list')
print(' ')
print('The ',len(celebs),'celebrities you entered were: ')
for name in celebs:
print(name)
main()
</code></pre>