代码:
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'
请告诉我我可以做些什么来改进代码。
答案 0 :(得分:0)
错误unsupported operand type(s) for +: 'int' and 'str'
表示Python无法将字符串添加到整数。在这种情况下,current
是整数," is the product"
是字符串。
要解决此问题,您可以执行以下操作:
print("%d is the product" % current * 13)