【发布时间】:2014-12-17 16:24:29
【问题描述】:
这是我的代码 -
import random
symbols=["+","-","x"]
question=0
score=0
choice=0
name=input("What is your name?")
while question<10:
r1=random.randint(1,10)
r2=random.randint(1,10)
s1=random.choice(symbols)
add=(r1+r2)
sub=(r1-r2)
times=(r1*r2)
print("What is ",+str(r1),+s1,+str(r2),)
ask=int(input())
if s1=="+":
if ask==add:
print("Correct")
score=score+1
else:
print("Incorrect")
if s1=="-":
if ask==sub:
print("Correct")
score=score+1
else:
print("Incorrect")
if s1=="x":
if ask==sub:
print("Correct")
score=score+1
else:
print("Incorrect")
print("Your score is: "+score,"out of 10")
我得到的错误是 -
What is your name?Emma
Traceback (most recent call last):
File "C:/Users/Emma/Documents/Python/Questions Maths.py", line 14, in <module>
print("What is ",+str(r1),+s1,+str(r2),)
TypeError: bad operand type for unary +: 'str'
【问题讨论】:
-
不要在你的打印语句中混用逗号,你应该没问题。
-
好的,你的问题是什么?
标签: python