2017-02-03 2 views
-2

私はプログラミングクラスの紹介者であり、私は非常にPythonでプログラミングしています。とにかく私の先生は基本的なことをするために整数メニューを作成するように私に依頼しました。2番目の整数が置かれた後にメニューを再表示しようとしています

だけでなく、私がトラブルに新しい整数を入れた後に再表示するには、私のメニューを取得したのです。

プログラムはメニューを経由して、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()を呼び出しているということです。

新しい番号を取得するたびにmenu()から呼び出す必要があります。修正

:素晴らしい

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() 
関連する問題