Python 我需要帮助制作这个随机测验生成器。我无法使循环或提问部分正常工作

Python 我需要帮助制作这个随机测验生成器。我无法使循环或提问部分正常工作,python,Python,所以我需要帮助循环和输入问题的答案,同时使问题每次产生不同的结果 answered = 0 correct = 0 import random ops = ['+', '-', '*',] num1 = random.randint(0,10) num2 = random.randint(0,10) operation = random.choice(ops) print(num1) print(operation) print(num2) maths = eval(str(num1) +

所以我需要帮助循环和输入问题的答案,同时使问题每次产生不同的结果

answered = 0
correct = 0
import random

ops = ['+', '-', '*',]
num1 = random.randint(0,10)
num2 = random.randint(0,10)
operation = random.choice(ops)

print(num1)
print(operation)
print(num2)

maths = eval(str(num1) + operation + str(num2))

while answered <= 10:
    print("what is" ,num1, operation, num2,)
    input`enter code here`
   if input == maths:
        answered = answered + 1
        correct = correct + 1
        print("correct")
    elif input != maths:
        answered = answered + 1
        print("incorrect")
应答=0
正确=0
随机输入
ops=['+'、'-'、'*'、]
num1=random.randint(0,10)
num2=随机的随机数(0,10)
操作=随机选择(ops)
打印(num1)
打印(操作)
打印(num2)
数学=eval(str(num1)+运算+str(num2))
当回答时,我认为应该是:

while answered <= 10:
    print("what is" ,num1, operation, num2,)
    input`enter code here`
    if input == maths: {
        answered = answered + 1
        correct = correct + 1
        print("correct")
        }
    elif input != maths: {
        answered = answered + 1
        print("incorrect")
        }

在回答时您应该将随机选择放入一个函数中,并在每个
if语句的末尾调用它,如下所示:

import random

answered = 0
correct = 0

ops = ['+', '-', '*',]
num1 = random.randint(0,10)
num2 = random.randint(0,10)
operation = random.choice(ops)

maths = eval(str(num1) + operation + str(num2))

combined = [num1, operation, num2]

def shuffle():
    global ops, num1, num2, operation, maths, combined
    ops = ['+', '-', '*',]
    num1 = random.randint(0,10)
    num2 = random.randint(0,10)
    operation = random.choice(ops)

    maths = eval(str(num1) + operation + str(num2))

    combined = [num1, operation, num2]


while answered <= 10:
    ans = int(input("what is {}".format(combined)))
    if ans == maths:
        answered += 1
        correct += 1
        print("Correct")
        print("Answered: ", answered, "Correct: ", correct)
        shuffle()
    elif ans != maths:
        answered = answered + 1
        print("Incorrect")
        shuffle()

然后可以完全删除组合的

除了添加花括号外,您没有做任何更改,上面的代码仍然会抛出语法错误。您需要将num1=和num2=行放在while循环的开头。另外,您需要查找输入是如何工作的(它是一个函数,它返回一个值),是否有任何方法可以删除方括号、逗号和倒逗号?当它不使用组合的
输出[4',-',4]时,请检查代码块下方我的答案的下半部分。
print("What is " ,num1, operation, num2)
ans = int(input())