2017-04-19 13 views
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

答えて

1

option=input('Pick your option: ')では、オプションは文字列です。あなたはint型に変換、または

if option=='1': 

し、それをテストすることができどちらか - 好き嫌いではないが、あなたは感謝「のelif」

+0

ヘクタールああを検討する必要があります!そしてええ、それは私が忘れている悪い習慣です。それを心に留めておく。 –

関連する問題