【发布时间】:2014-11-04 15:04:25
【问题描述】:
这适用于 Python 3.3。当我运行这个程序时,它总是运行子程序“func_addition”。
我想让它从列表中随机选择一个子例程。所以,它会问一个随机的算术问题。
import random
def func_addition():
a = random.randint(1,25)
b = random.randint(1,25)
c=a+b
answer=int(input("What is "+str(a)+" + "+str(b)+" ? "))
def func_subtraction():
d = random.randint(10,25)
e = random.randint(1,10)
f=d-e
answer=int(input("What is "+str(d)+" - "+str(e)+" ? "))
def func_multiplication():
g = random.randint(1,10)
h = random.randint(1,10)
i=g*h
answer=int(input("What is "+str(g)+" X "+str(h)+" ? "))
my_list=[func_addition() , func_subtraction() , func_multiplication()]
name=input("What is your name ? ")
print("Hello "+str(name)+" and welcome to The Arithmetic Quiz")
print(random.choice(my_list))
【问题讨论】:
标签: python list random python-3.3 subroutine