#10-3访客'''提示用户输入姓名,用户做出响应后将名称写入user_name.txt文件'''
filename='user_name.txt'#以附加模式打开文件,给文件添加内容时,不会覆盖原有文件withopen(filename,'a')as file_object:
name=input("Please input your name: ")
file_object.write(name +'\n')
#10-4访客名单'''用户输入姓名后,在屏幕上打印一句问候语,并在user_name.txt文件中添加一条方访客信息'''
filename='user_name.txt'
name=input("Please input your name(When you enter a blank, the programming ends.): ")while name:if name==' ':breakprint('hello, '+ name)withopen(filename,'a')as file_object:
file_object.write(name +' visited \n')
name=input("Please input your name: ")