擅长:python、mysql、java
<p>以下是解决您问题的方法:</p>
<pre><code>import time
import random
question = 0
score = 0
name = input("What is your full name?")
print ("Hello " + name, "welcome to The Arithmetic Quiz")
time.sleep(2)
operand1 = list(range(2, 12))
operand2 = list(range(2, 12))
while question < 10:
num1 = random.choice(operand1)
num2 = random.choice(operand2)
print(str(num1) + "+" + str(num2))
user_answer = int(input())
expected_answer = int(num1) + int(num2)
if user_answer == expected_answer:
print('This is correct!!')
score = score + 1
question = question + 1
else:
print('This is incorrect!!')
question = question + 1
print("\nYour score is " + str(score))
</code></pre>
<p>这里不需要operands变量,而是可以将+运算符作为字符串本身传递。
另外,由于操作数1和操作数2是作为列表传递的,而不是作为int传递的,所以预期的\u answer变量无法解析求和</p>