简体   繁体   English

如何修复 TypeError: +: 'int' 和 'str' 不支持的操作数类型

[英]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.

相关问题 如何解决以下错误 - TypeError: unsupported operand type(s) for -: 'int' and 'str' - how do I resolve the following error - TypeError: unsupported operand type(s) for -: 'int' and 'str' 如何修复 TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'? - How do I fix TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'? 如何修复numpy TypeError:不支持的操作数类型-:&#39;str&#39;和&#39;str&#39; - How to fix numpy TypeError: unsupported operand type(s) for -: 'str' and 'str' 类型错误:&lt;&lt;:&#39;str&#39; 和 &#39;int&#39; 的操作数类型不受支持 - TypeError: unsupported operand type(s) for <<: 'str' and 'int' TypeError:-:“ int”和“ str”不支持的操作数类型 - TypeError: unsupported operand type(s) for -: 'int' and 'str' 类型错误:不支持 / 的操作数类型:&#39;str&#39; 和 &#39;int&#39; (2) - TypeError: unsupported operand type(s) for /: 'str' and 'int' (2) TypeError:-:“ str”和“ int”的不受支持的操作数类型 - TypeError: unsupported operand type(s) for -: 'str' and 'int' TypeError:+ =不支持的操作数类型:“ int”和“ str” - TypeError: unsupported operand type(s) for +=: 'int' and 'str' typeerror 不支持 / &#39;str&#39; 和 &#39;int&#39; 的操作数类型 - typeerror unsupported operand type(s) for / 'str' and 'int' TypeError:-:“ str”和“ int”的不受支持的操作数类型 - TypeError:unsupported operand type(s) for -: 'str' and 'int'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM