<p>我在输出中更改了一些内容,您应该使用.format作为变量,而不是其他任何东西。</p>
<p>现在应该可以了。。。</p>
<pre><code>import random
import operator
def quiz():
print('Welcome. This is a 10 question math quiz\n')
name = input("Please enter your name\n")
print("Hello", name,"\n Let's begin the quiz!")
score = 0
for i in range(10):
correct = askQuestion()
if correct:
score = score + 1
print('Correct!')
print ("Score is {}".format(score))
else:
print('Incorrect!')
print ("Score is {}".format(score))
print("{}, your score was {}/10".format(name, score))
def askQuestion():
answer = randomCalc()
guess = float(input())
return guess == answer
def randomCalc():
ops = {'+':operator.add,
'-':operator.sub,
'*':operator.mul,
'/':operator.truediv}
num1 = random.randint(0,11)
num2 = random.randint(1,11)
op = random.choice(list(ops.keys()))
answer = ops.get(op)(num1,num2)
print('What is {} {} {}?'.format(num1, op, num2))
return answer
quiz()
#askQuestion()
#randomCalc()
</code></pre>