我应该在 python 中编写一个程序,询问用户他们想要多少个乘法问题,它随机给他们问题的值从 1 到 10。然后它吐出他们正确的百分比。我的代码不断重复相同的一组数字,而且它也不会停留在用户要求的数字上。你能告诉我有什么问题吗?
import random
import math
gamenumber = int(input("How many probems do you want?\n"))
num_1 = random.randint(1,10)
num_2 = random.randint(1,10)
def main():
random.seed()
count = 0
while count < gamenumber:
guess = int(input("What is " + str(num_1) + "x" + str(num_2) + "."))
answer = str(num_1*num_2)
correct = guess == answer
if guess == answer:
print("Correct!")
else wrong:
print("Sorry, the answer is", answer, ".")
result = correct/wrong
print("You got ", "%.1f"%result, "of the problems.")
main()