Python学习(二)常见问题(5):TypeError: unsupported operand type(s) for +: 'int' and 'str'

版权声明:版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37960324/article/details/84138594

Python学习(二)常见问题(5):TypeError: unsupported operand type(s) for +: 'int' and 'str'

 

在键入数值进行相加运算时,报了这样一个错误

类型错误:不支持操作类型为整数和字符

错误分析:sum=sum+input() 未被系统识别致程序错误

解决方法:给键入的数,声明整数

sum=sum+int(input()) 即可

执行结果

猜你喜欢

转载自blog.csdn.net/qq_37960324/article/details/84138594