2017-02-03 37 views
-2

夥計我是一個學生在編程類的介紹,所以我非常想用python進行編程。無論如何,我的老師要求我們創建一個整數菜單來做基本的事情。嘗試重新顯示我的菜單後,放入第二個整數

以及我無法讓我的菜單中選擇一個新的整數放入後重新顯示。

該計劃將通過菜單,然後displaymenu,然後我可以選擇1到回去的菜單,但一旦我輸入一個新的整數程序退出我想我需要知道如何讓它返回到displaymenu沒有退出。希望我已經解釋得很好,以幫助解決我的問題。

這裏是到目前爲止我的代碼:

def menu(): 
    while True: 
     try: 
      print(" Hello, and welcome to the integer fun menu\n") 
      num=int(input(" to begin please enter in a non-negative integer--->")), print("\n") 
      break 
     except ValueError: 
      print("\nThat is not a valid response please input another\n") 
def displaymenu(): 
    while True: 
     try: 
      choice=int(input("""Thank you now please choose from the options listed below.\n 
         1. Enter a new integer 
         2. Find all evens, odds and zeroes 
         3. sum up all numbers in the integer 
         4. Quit \n""")) 
      if choice == 1: 
       menu() 
       break 
      elif choice == 2: 
       Evens() 
       break 
      elif choice == 3: 
       Sums() 
       break 
      elif choice == 4: 
       break 
      else: 
       print("I do not understand please choose again") 
       displaymenu() 
     except ValueError: 
      print("I do not understand please choose again") 
    exit 





menu() 
displaymenu() 
+0

真棒,謝謝你的幫助,你不知道我想多久才能這項工作。我試過如果這麼多次哈哈無論如何再次感謝你。 – Mitchellsprock

回答

0

的問題是,您所呼叫displaymenu()只有一次。

您必須在每次獲得新號碼時從菜單()中調用它。

修改:

def menu(): 
     while True: 
      try: 
       print(" Hello, and welcome to the integer fun menu\n") 
       num=int(input(" to begin please enter in a non-negative integer--->")), print("\n") 
       displaymenu() 
       break 
      except ValueError: 
       print("\nThat is not a valid response please input another\n") 
    def displaymenu(): 
     while True: 
      try: 
       choice=int(input("""Thank you now please choose from the options listed below.\n 
          1. Enter a new integer 
          2. Find all evens, odds and zeroes 
          3. sum up all numbers in the integer 
          4. Quit \n""")) 
       if choice == 1: 
        menu() 
        break 
       elif choice == 2: 
        Evens() 
        break 
       elif choice == 3: 
        Sums() 
        break 
       elif choice == 4: 
        break 
       else: 
        print("I do not understand please choose again") 
        displaymenu() 
      except ValueError: 
       print("I do not understand please choose again") 
     exit 
    menu() 
相關問題