2017-03-09 52 views
0

enter image description here我想知道如何在循環中的每個mainmenu()後停止顯示單詞「無」。在循環中執行主菜單後顯示「無」文本

import time 
import add 
import sub 
import mul 
import div 

def mainmenu(): 
    print 30 * "-" , "MENU" , 30 * "-" 
    print "1. Add" 
    print "2. Substraction" 
    print "3. Multiplication" 
    print "4. Division" 
    print "5. SquareRoot" 
    print "6. Exit" 
    print 67 * "-" 

    while True: 
     try: 
      print mainmenu() 
      choice = raw_input("Enter your correct number [1-7]: ") 
      if choice == "1": 
       firstNum=input ("\nPlease enter first number : ") 
       secondNum=input("Please enter Second number: ") 
       print "Answer is " , add.ad(firstNum,secondNum) 
       time.sleep(3) 
      elif choice == "2": 
       firstNum=input ("\nPlease enter first number : ") 
       secondNum=input("Please enter Second number: ") 
       print "Answer is " ,sub.su(firstNum,secondNum) 
       time.sleep(3) 
      elif choice == "3": 
       firstNum=input ("\nPlease enter first number : ") 
       secondNum=input("Please enter Second number: ") 
       print "Answer is ",mul.mu(firstNum,secondNum) 
       time.sleep(3) 
      elif choice == "4": 
       firstNum=input ("\nPlease enter first number : ") 
       secondNum=input("Please enter Second number: ") 
       print "Answer is " ,div.di(firstNum,secondNum) 
       time.sleep(3) 
      elif choice == "5": 
       firstNum=input ("\nPlease enter first number : ") 
       print "Answer is " ,sqr(firstNum) 
       time.sleep(3) 
      elif choice == "6": 
       break 
     except ValueError: 
      print ("Oops!! that was not a valid number. Try again....") 

回答

0

刪除mainmenu()之前的print語句。只需調用函數。

mainmenu() #just call function. 
choice = raw_input("Enter your correct number [1-7]: ") 
0

它由線

print mainmenu() 

由於函數的MainMenu()不返回值(因此None)引起的。