2015-08-20 43 views
-5

對不起我最後一個失敗的問題,但這次我想知道如何隨機選擇一個函數。例如。加法,減法等......我基本上希望能夠隨機地從函數設置中提出任何問題。這裏是代碼:Python「def」問題

#Maths Helper Program 
import random 
def Welcome(): 
    print ("Welcome to Rory's Maths Assistance Program!") 
    print ("You may select test(T) mode or pratise(P) mode to begin") 
    x = input ("Please enter your selection T/P : ") 
    if x == "T": 
     Test() 
    elif x == "P": 
     Practise() 
    else : 
     print("Your choice was not an option...") 
     print("") 
     Welcome() 

def Difficulity(): 
    print ("Please select either Easy(E), Medium(M), or Hard(H) difficulty to begin") 


def Addition(): 
    a = random.randint(0,20) 
    b = random.randint(0,20) 
    d = a + b 
    c = input("What is " + str(a) + "+" + str(b) + "? ") 
    if int(c) == int(d): 
     print ("Correct!") 
    elif c != d: 
     print ("Incorrect, the correct answer was " + str(d)) 

def Subtraction(): 
    a = random.randint(0,20) 
    b = random.randint(0,20) 
    d = a - b 
    c = input("What is " + str(a) + "-" + str(b) + "? ") 
    if int(c) == int(d): 
     print ("Correct!") 
    elif c != d: 
     print ("Incorrect, the correct answer was " + str(d)) 

def Multiplication(): 
    a = random.randint(0,10) 
    b = random.randint(0,10) 
    d = a * b 
    c = input("What is " + str(a) + "x" + str(b) + "? ") 
    if int(c) == int(d): 
     print ("Correct!") 
    elif c != d: 
     print ("Incorrect, the correct answer was " + str(d)) 

def Division(): 
    a = random.randint(0,10) 
    b = random.randint(0,10) 
    d = a * b 
    c = input("What is " + str(d) + "÷" + str(a) + "? ") 
    if int(c) == int(b): 
     print ("Correct!") 
    elif c != b: 
     print ("Incorrect, the correct answer was " + str(b)) 

def Practise(): 
    a = int(input("How many questions would you like? ")) 
    while a <= 0: 



Welcome() 
+1

'X =輸入( 「請輸入您的選擇T/P:」'應該有一個密切的')' – muddyfish

+2

您應該使用支持語法高亮的編輯器... – kay

回答

1
def Welcome(): 
    print ("Welcome to Rory's Maths Assistance Program!") 
    print ("You may select test(T) mode or pratise(P) mode to begin") 
    x = input ("Please enter your selection T/P : " 

看起來你錯過了上最後一行括號。

def Welcome(): 
    print ("Welcome to Rory's Maths Assistance Program!") 
    print ("You may select test(T) mode or pratise(P) mode to begin") 
    x = input ("Please enter your selection T/P : ") 
+0

三江源:D殺了我:d –