이 내 코드입니다 -형식 오류 : 단항 +에 대한 잘못된 피연산자 유형 : 'STR'는
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'
이 인쇄에 쉼표를 혼합하지 마십시오 성명서와 당신은 잘되어야합니다. – BlackVegetable
좋아요, 그럼 네 질문은 뭐니? – aestrivex