-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()
'X =输入( “请输入您的选择T/P:”'应该有一个密切的')' – muddyfish
您应该使用支持语法高亮的编辑器... – kay