我正在使用 Python 3.2 只是为了让您知道我在做什么,这是分配: ~ random 模块中的函数 random.randint 可用于从一系列值中生成整数。例如,random.randint(1,6) 以相等的概率产生值 1 到 6。一个简单的辅导程序可能会随机选择 0 到 12 之间的两个数字并提出如下问题:6 乘以 8 是多少?收到用户回复后,计算机会检查答案是否正确并给出鼓励性的评论。编写一个程序,循环 10 次产生这种形式的问题,并在最后给用户打分。
这是我的程序中的内容:
print ("Hello. Let's begin")
for i in range (1,10):
from random import randint
x=randint (0,12)
y=randint (0,12)
print (x,"*" y,"=?")
product= int(input ("What is the product?")
if (product==x*y):
print ("Awesome! That is correct!")
else:
print ("Sorry, that is not correct, but let's try another one!")
我拥有所有这一切。它向用户询问一个随机乘法问题并回答十次。我不明白该怎么做是最后给用户一个分数。我正在集思广益,但真正奏效的并不多。我想我必须做类似的事情:
score=
但我不知道如何告诉程序计算正确答案的数量......我说 score=number of if 吗?
然后当我打印分数时,我可以说:
if (score>5) :
print: ("Great job! You scored a",score,"out of ten!")
else:
print: ("Not the best score, but you can try again! You scored a",score,"out of ten.")
或者有没有更简单的方法来做到这一点?