10-4 访客名单:
编写一个while 循环,提示用户输入其名字。用户输入其名字后,在屏幕上打印一句问候语,并将一条访问记录添加到文件guest_book.txt 中。确保这个文件中的每条记录都独占一行。
file_name='guest_book.txt'
active=True
while active:
print("enter username: ")
username=input()
print("hello "+username+"!\n")
with open(file_name,'a') as file_object:
file_object.write(username+"\n")
print("continue? (Y/N) ")
ifcontinue=input()
if ifcontinue == 'N' or ifcontinue=='n':
active=False
本文介绍了一个使用Python编写的简单程序,该程序通过while循环收集用户的姓名并将其记录在一个名为guest_book.txt的文件中。每条记录独立成行,便于后续查看及管理。
3367

被折叠的 条评论
为什么被折叠?



