Python随机数学生成器失败

Python随机数学生成器失败,python,random,numbers,generator,Python,Random,Numbers,Generator,好的,我现在遇到了我的代码的问题,当我运行我的代码时,它不会给用户回答的机会 print ("what is your username") name = input () .title() print (name, "welcome") import random score=0 question=0 for i in range(10): ops = ["+", "-", "*"] num1 = random.randint (0,10) num2 = random.randint (0

好的,我现在遇到了我的代码的问题,当我运行我的代码时,它不会给用户回答的机会

print ("what is your username")
name = input () .title()
print (name, "welcome")
import random
score=0
question=0
for i in range(10):

 ops = ["+", "-", "*"]
num1 = random.randint (0,10)
num2 = random.randint (0,10)
oparator = random.choice(ops)
Q=(str(num1)+(oparator)+(str(num2)))
print (Q)


if oparator =='+':
    answer=num1+num2
    if Q == answer:
        print ("correct")
        score=score+1
    else:
         print ("incorrect")


if oparator =='-':
    answer=num1-num2
    if Q == answer:
        print ("correct")
        score=score+1
    else:
         print ("incorrect")


if oparator =='*':
    answer=num1*num2
    if Q == answer:
        print ("correct")
        score=score+1
    else:

        print ("incorrect")
我不确定如何解决这个问题,因为我是编程新手。 它不会让用户猜测,只会打印不正确的内容

what is your username
kurt
Kurt welcome
2*0
incorrect
>>> 
您正在使用int(num1和num2)和来自ops的字符串,请按如下方式进行修复:

input (str(num1)+(ops)+str(num2)) 
在Python中,您不能添加字符串和int(通常不是您想要的),Python是显式的,因此您需要显式地将数字转换为字符串。这样可读性更好。

您使用的是int(num1和num2)和来自ops的字符串,请按如下方式进行修复:

input (str(num1)+(ops)+str(num2)) 

在Python中,您不能添加字符串和int(通常不是您想要的),Python是显式的,因此您需要显式地将数字转换为字符串。这样更容易阅读。

如果答案有用,你能接受吗?如果答案有用,你能接受吗?