python unsupported operand type(s) for /: 'str' and 'str' can only concatenate str (not int) to s
报错:
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)
不能带+号#怪我以前看了错误教程
python unsupported operand type(s) for /: 'str' and 'str' can only concatenate str (not int) to s相关推荐
- 踩坑中:TypeError: unsupported operand type(s) for /: 'str' and 'int'
在网上查看了很多博客,首先从报错提示来讲TypeError: unsupported operand type(s) for /: 'str' and 'int',明确了是类型错误:不支持操作类型为整 ...
- 成功解决ret = ret / rcountTypeError: unsupported operand type(s) for /: ‘str‘ and ‘int‘
成功解决ret = ret / rcountTypeError: unsupported operand type(s) for /: 'str' and 'int' 目录 解决问题 解决思路 解决方 ...
- python报错TypeError: unsupported operand type(s) for -: ‘decimal.Decimal‘ and ‘float‘的解决方法
问题描述 在编写python代码时,进行小数位相减时出现 TypeError: unsupported operand type(s) for -: 'decimal.Decimal' and 'fl ...
- 解决报错TypeError:unsupported operand type(s) for +: ‘NoneType‘ and ‘str‘
文章目录 一.问题描述 二.解决方案 Reference 一.问题描述 from pyspark.sql.types import StringType@udf(returnType = String ...
- apex安装报错:TypeError: unsupported operand type(s) for +: ‘NoneType‘ and ‘str‘
参考解决方法:TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' · Issue #990 · NVIDIA/apex ...
- Python PIP Install throws TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
Python PIP Install throws TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
- 解决Python中sum函数出现的TypeError: unsupported operand type(s) for +: 'int' and 'list'错误问题
当在Python中运行sum函数时,会出现"TypeError: unsupported operand type(s) for +: 'int' and 'list'"这样的问题 ...
- 解决pandas(Python)的报错:unsupported operand type(s) for -: ‘datetime.date’ and ‘Timestamp’
在使用Pandas包的时候,遇到时间加减出现的报错 'datetime.date'是datetime的一种时间格式: 'Timestamp'(注意是大写的字母)是Pandas的一种时间格式. 这两个虽 ...
- Django问题:TypeError: unsupported operand type(s) for -: ‘str‘ and ‘float‘
Django问题:TypeError: unsupported operand type(s) for -: 'str' and 'float Traceback (most recent call ...
最新文章
- DDoS攻击惯犯图鉴
- Designing Virtual Connect for vSphere 5.x
- mint java_Oracle Java 12 (JDK 12)在Ubuntu、Linux Mint或Debian(使用PPA)安装配置
- 本田思域自动挡的使用技巧
- python 日期格式打印_Python打印格式
- 阶段5 3.微服务项目【学成在线】_day01 搭建环境 CMS服务端开发_26-页面查询接口测试-Postman...
- 20天通过中级软件设计师攻略(附资料)
- 01将乌班图系统安装到U盘,实现即插即用
- ch341a烧录器zip_CH341A编程器
- Win10 锁屏自动息屏解决方案
- 群晖 NAS 中的 Audio Station 一直不能加载 NAS 中的音乐问题的解决方法及自定义音乐库文件夹方法.md
- 爬虫练习三:爬取链家二手房信息
- 带宽在计算机系统中的意义,带宽是什么意思?
- Centos 7 环境下将修改后的MAC地址永久保存
- PhpSpreadsheet读取excel
- 一个新手学着重装系统之路
- vue点击按钮打开新页签,并传参
- CommandArgument的一种用法
- python 董付国程序设计基础与应用第三版pdf_Python 程序设计基础(董付国 著)完整版PDF[6MB]...
- 健身软件的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告