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)
答案 0 :(得分:1)
在option=input('Pick your option: ')
中,option是一个字符串。您可以将其转换为int,或使用
if option=='1':
并且 - 不要挑剔,但你可能想要考虑'elif'