版权声明:转载请声明原文链接地址,谢谢! https://blog.csdn.net/weixin_42859280/article/details/84571058
报错:
TypeError: can only concatenate str (not “int”) to str
TypeError: unsupported operand type(s) for /: ‘str’ and 'str’
python代码部分~
正确代码:
a = int(input('你离开几小时(h):'))
b = int(input('你离开几分钟(min):'))
c = int(input('几秒钟循环一次(s):'))
m = a*60*60+b*60
s = (a*60*60+b*60)/c
print("全部的秒数为:",m)
print("次数为:",s)
最后的执行情况:
失败了好多次~
失败1:
所报错误:
Traceback (most recent call last):
File "C:\Users\HWP\Desktop\1次.py", line 5, in <module>
s = (a*60*60+b*60)/c
TypeError: unsupported operand type(s) for /: 'str' and 'str'
代码:
a = input('你离开几小时(h):')
b = input('你离开几分钟(min):')
c = input('几秒钟循环一次(s):')
m = a*60*60+b*60
s = (a*60*60+b*60)/c
print("全部的秒数为:"+m)
print("次数为:"+s)
因为:
正确的代码,把input的内容,转变为整数(或其它类型的数):
- a = int(input())
- a = float(input())
前面再加一个字符类型~
#这个代码并不全部正确,因为输出那里有问题~失败2讲到啦~
a = int(input('你离开几小时(h):'))
b = int(input('你离开几分钟(min):'))
c = int(input('几秒钟循环一次(s):'))
m = a*60*60+b*60
s = (a*60*60+b*60)/c
print("全部的秒数为:"+m)
print("次数为:"+s)
失败2:
所报错误:
Traceback (most recent call last):
File "C:\Users\HWP\Desktop\1次.py", line 6, in <module>
print("全部的秒数为:"+m)
TypeError: can only concatenate str (not "int") to str
代码:
a = int(input('你离开几小时(h):'))
b = int(input('你离开几分钟(min):'))
c = int(input('几秒钟循环一次(s):'))
m = a*60*60+b*60
s = (a*60*60+b*60)/c
print("全部的秒数为:"+m)
print("次数为:",s)
就因为这一句:print(“全部的秒数为:”+m)
正确的代码是,
print("全部的秒数为:",m)
不能带+号#怪我以前看了错误教程