Python 我如何将随机生成的算术循环10次?这是到目前为止我的代码

Python 我如何将随机生成的算术循环10次?这是到目前为止我的代码,python,random,Python,Random,您可以简单地添加一个for循环,在代码上迭代10次 import random score = 0 ops = ['+','-','*'] num1 = random.randint(1,9) num2 = random.randint(1,9) operation = random.choice(ops) print(num1) print(operation) print(num2) user = int(input("")) if operation == "+": answer

您可以简单地添加一个for循环,在代码上迭代10次

import random 
score = 0
ops = ['+','-','*']
num1 = random.randint(1,9)
num2 = random.randint(1,9)
operation = random.choice(ops)
print(num1)
print(operation)
print(num2)
user = int(input(""))
if operation == "+":
    answer = num1 + num2
elif operation == "-":
    answer = num1 - num2
elif operation == "*":
    answer = num1 * num2

if user == answer:
    print("correct")
    score = score + 1
else:
        print("Incorrect")
print (score)

欢迎来到堆栈溢出!请编辑您的问题,以准确解释您希望此程序返回的内容,因为问题并不完全清楚,这对于理解您的问题至关重要。我的意思是,我必须为基本算术测验生成10个随机问题。代码是有效的,我只是对如何生成10个问题感到困惑,因为目前的代码生成1个问题,然后结束。谢谢。试着查找循环。谢谢,我应该试着查找循环如何工作xD。老兄。
import random 
score = 0
ops = ['+','-','*']

for i in range(10):
    num1 = random.randint(1,9)
    num2 = random.randint(1,9)
    operation = random.choice(ops)
    print(num1)
    print(operation)
    print(num2)
    user = int(input(""))
    if operation == "+":
        answer = num1 + num2
    elif operation == "-":
        answer = num1 - num2
    elif operation == "*":
        answer = num1 * num2

    if user == answer:
        print("correct")
        score = score + 1
    else:
        print("Incorrect")
    print (score)