擅长:python、mysql、java
<p>删除paren,否则在创建列表时将调用所有函数。你知道吗</p>
<pre><code>my_list = [func_addition , func_subtraction , func_multiplication]
name = input("What is your name ? ")
print("Hello {} and welcome to The Arithmetic Quiz".format(name))
chc = random.choice(my_list) # pick random function
chc() # call function
</code></pre>
<p>如果您不知道如何使用变量,我将执行以下操作来验证答案:</p>
<pre><code>def func_addition():
a = random.randint(1,25)
b = random.randint(1,25)
c = a + b
answer = int(input("What is {} + {} ? ".format(a,b)))
if answer == c:
print("Well done, that is correct")
else:
print(" Sorry, that is incorrect, the correct answer is {}".format(c))
</code></pre>