0
def write():
writefile=input("Please enter the last name: ")
name=input("Please enter your name:")
street=input("Enter House Number and Street Name:")
city=input('Enter City, State and ZIP:')
home=input('Enter Home Phone Number:')
mobile=input('Enter Cell Phone Number:')
outfile=open('C:\\Users\\Force\workspace\addressbook.txt','w')
outfile.write("Added "+name+writefile)
outfile.write(street+city+home+mobile)
outfile.close()
def read():
phonebook=open("C:\\Users\\Force\workspace\addressbook.txt",'r')
numEntries=0
lastName=phonebook.readline().rstrip()
while lastName!='':
firstName=phonebook.readline().rstrip()
street=phonebook.readline().rstrip()
city=phonebook.readline().rstrip()
homephone=phonebook.readline().rstrip()
mobilephone=phonebook.readline().rstrip()
numEntries=numEntries+1
LastName=phonebook.readline().rstrip()
def menu():
print('1: Look up person by last name')
print('2: Add a person to the address book')
print('3: Quit')
option=input('Pick your option: ')
if option==1:
read()
if option==2:
write()
if option==3:
print("Good bye!")
menu()
每次它帶給我的菜單我嘗試選擇它只是終止程序的選項的時間。不知道它是我的用戶定義的函數,文本文件的打開還是全部。 (使用Pydev的3.6)如何寫一個菜單驅動的Python程序,有一個地址簿的作品? Pydev的
哦哈哈謝謝!是的,這是一個我不斷忘記的壞習慣。在那裏記住這一點。 –