2016-06-30 5 views
-1

defメニュー()と 'menu()'コードを追加する前に私のコードが正常に機能しましたが、なぜではないかについての任意のアイデア?私はちょうど '>>>'! FYI:すべてのインデントは似たようなコードでうまくいき、 'def'関数がコードに導入される前にうまくいきました。defコードが何らかの理由で自分のコードに影響を与えているようです

def menu() : 
    print("Please enter the number corresponding with the option you would like to pick.") 
    print("1. Record Purchase(s)") 
    print("2. Retrieve Previous Purchase(s)") 
    option=input("> ") 

if option == "1": 
     customer_id1=input("Customer ID: ") 
     file=open(customer_id1.capitalize()+".txt","a") 
     info=input("Please enter all purchases seperated by commas: ") 
     file.write(info+"\n") 
     file.close() 
     print("PURCHASE RECORD SUCCESSFUL") 
     import time 
     time.sleep(5) 
     menu() 

if option == "2": 
     customer_id2=input("Customer ID: ") 
     file=open(customer_id2+".txt","r") 
     print(file.read()) 
     time.sleep(10) 
     menu() 

else: 
     print("Sorry, that doesnt seem to be an option, returning to menu.") 
     menu() 
+0

_「すべての字下げが正しい」_:これはあなたのファイルに当てはまる可能性があります。ただし、ここに示すコードではインデントが正しくありません。 – John1024

答えて

0

あなたのコメントから>>>私はあなたがpythonシェルでこれを実行していると仮定しています。その場合、実際にmenu()を呼び出すことは決してありません。あなたはそれを定義するだけです。それを呼び出すには、関数宣言の範囲外にmenu()を置く必要があります。

関連する問題