[英]How do I fix TypeError: unsupported operand type(s) for +: 'int' and 'str'
I'm coding a calculator and when I ran the program this Error message appeared:我正在编写一个计算器,当我运行程序时,出现了这个错误消息:
Traceback (most recent call last):
File "/Users/sergioley-languren/Documents/itt/independent_projects/Mathematical_Calculator.py", line 66, in <module>
print(x + "+" + y + "=" + mathResult + ".") ; sleep(float(speed))
TypeError: unsupported operand type(s) for +: 'int' and 'str'
This here is the code where the error appears:这是出现错误的代码:
print("type in your addition problem with your x variable first. (x variable = your first number) CAUTION: This calculator only supports 2 numbers at the moment.") ; sleep(float(speed))
x = int(input())
print("Type in your y variable.") ; sleep(float(speed))
y = int(input())
mathResult = x + y
print(x + "+" + y + "=" + mathResult + ".") ; sleep(float(speed))
In python3: print(x, "+", y, "=", mathResult, ".")
在 python3 中:
print(x, "+", y, "=", mathResult, ".")
Just try putting commas instead of +
:只需尝试使用逗号而不是
+
:
print x , "+" , y , "=" , mathResult , "."
If you are on python 3.6.如果您使用的是 python 3.6。
print(f"{x} + {y} = {mathResult}.")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.