def代码似乎对我的代码做了一些我无法理解的事情

时间:2016-06-30 19:42:26

标签: function python-3.x

在添加' def菜单()'之前,我的代码运行正常。代码和' menu()'代码,但现在它似乎没有工作!任何想法为什么不呢?我只是得不到回报,只是'>>>'!仅供参考:所有缩进都是正确的,因为它们在类似的代码上都很好,并且在“定义”之前工作正常。函数被引入代码。

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 个答案:

没有答案