【问题标题】:An error with my code that I just cant figure out [duplicate]我的代码有一个错误,我只是想不通[重复]
【发布时间】:2018-08-20 16:26:15
【问题描述】:

代码:

current = input (" Now subtract it by 1. Uh-Oh, My calculator is broken, please tell me what the difference is.")
current = int(current)

print (" OK, my calulator is up and running. We must multiply the number  with 13. Its alright, I have the answer here.")
print (current*13 + " is the product") 

错误信息:

Traceback (most recent call last):
File "/home/pi/Desktop/birthday trick.py", line 13, in <module>
print (current*13 + " is the product")
TypeError: unsupported operand type(s) for +: 'int' and 'str'

请告诉我我可以做些什么来改进我的代码。

【问题讨论】:

    标签: python linux


    【解决方案1】:

    错误unsupported operand type(s) for +: 'int' and 'str' 表示 Python 无法将字符串添加到整数。在这种情况下,current 是一个整数," is the product" 是字符串。

    要解决此问题,您可以执行以下操作:

    print("%d is the product"  % current  * 13)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-18
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      • 1970-01-01
      相关资源
      最近更新 更多