TypeError: bad operand type for unary +: 'str' python

TypeError: bad operand type for unary +: 'str' python

number=int(input("Please enter a number:     "))

for b in range(1,11):
    b=int(b)
    output=int (number) *int (b)
    print(+str (b) +" times "+ str (number) +" is " +output)

我希望程序请求一个数字,然后打印它的时间 table 最多 10* 个数字,但是我一直收到这个错误。顺便说一句,我正在做 GCSE 计算。

Traceback (most recent call last):
File "C:\Users\jcowp_000\Documents\School\Lutterworth\Computing\Documents_-_-___________---________---______-_-_-_-__-__\Python\Python manual tasks.py", line 21, in <module>
print(+str (b) +" times "+ str (number) +" is " +output)
TypeError: bad operand type for unary +: 'str'

我想这就是你想要做的:

number = int(input("Please enter a number:     "))

for b in range(1,11):
    output = int(number) * b   # b is already an int, you can use it directly in computations
    print(str(b) + " times " + str(number) + " is " + str(output))

请注意 +str(b) 是不正确的语法,还请注意您不能将 " is"output 连接起来,后者是 stroutput 是 [=15] =].

number=int(input("Please enter a number:     "))

for b in range(1,11):
    b=int(b)
    output=int (number) *int (b)
    print(b, "times",number,"is",output)