Python练习题 10-3~10-4 访客问题

来源:互联网 发布:工业控制网络 pdf 编辑:程序博客网 时间:2024/06/07 17:47

10-3 访客:编写一个程序,提示用户输入其名字;用户作出响应后,将其名字写
入到文件 guest.txt 中。
10-4 访客名单:编写一个 while 循环,提示用户输入其名字。用户输入其名字后,
在屏幕上打印一句问候语,并将一条访问记录添加到文件 guest_book.txt 中。确保这个
文件中的每条记录都独占一行。

guest.py:

Hint="please enter your name :"control=1while control:    Name=input(Hint.title())    if Name=='#':        break        file.close()    with open('guest.txt','a') as file:        file.write(Name.title()+'\n')

guest.txt__first

guest.txt_last

WeiLianXin

不知道为什么会多出一个空行。。。