抱歉我最后一次失败的问题,但这次我想知道如何随机选择一个功能。例如。加法,减法等...我基本上希望能够从设置的函数中随机询问任何问题。这是代码:
#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()
答案 0 :(得分: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 : ")