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