python unsupported operand type(s) for /: 'str' and 'str' can only concatenate str (not int) to s

news/2024/7/3 2:25:59

报错:
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)

最后的执行情况:
V0L3dlaXhpbl80Mjg1OTI4MA==,size_16,color_FFFFFF,t_70)

失败了好多次~
失败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的内容,转变为整数(或其它类型的数):

  1. a = int(input())
  2. 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)

不能带+号#怪我以前看了错误教程


http://lihuaxi.xjx100.cn/news/266767.html

相关文章

MyBatis-Plus为啥这么牛?

点击上方蓝色“方志朋”&#xff0c;选择“设为星标”回复“666”获取独家整理的学习资料&#xff01;转自&#xff1a;ThinkYi链接&#xff1a;http://cnblogs.com/thinkYi/p/13723035.html前言大家有用过MyBatis-Plus&#xff08;简称MP&#xff09;的都知道它是一个MyBatis的…

超赞!arXiv论文如何一键链接解读视频,这个浏览器扩展帮你实现

点击上方“小白学视觉”&#xff0c;选择加"星标"或“置顶”重磅干货&#xff0c;第一时间送达有了这个浏览器扩展&#xff0c;读者就可以在 arXiv 论文页面直接链接到解读视频&#xff0c;真是太方便了。阅读 arXiv 论文时&#xff0c;我们可能会被冗长的篇幅以及有…

1 sec on Large Judge (java): https://github.com/l...

1 sec on Large Judge (java): https://github.com/leoyonn/leetcode/blob/master/src/q029_substring_of_all_words/Solution.java转载于:https://www.cnblogs.com/codingtmd/archive/2013/03/31/5079017.html

清华博士的逆袭之路:从收到延毕警告到顶刊发文,我蛰伏了4年

点击上方“视学算法”&#xff0c;选择加"星标"或“置顶”重磅干货&#xff0c;第一时间送达本文来源&#xff1a;北京日报 记者 任敏、清华大学“高考&#xff0c;他以本地理科状元的成绩考上清华&#xff1b;直升读博前4年&#xff0c;一作发表文章数为0&#xff0…

AI视觉大牛朱松纯担任北大AI研究院院长,提出通过构建大任务平台走向通用AI...

整理 | AI科技大本营编辑部据北京大学新闻网9月24日报道&#xff0c;AI视觉顶级学者朱松纯正式任职北京大学讲席教授、人工智能研究院院长。朱松纯表示&#xff0c;他与北大、清华的相关学者一直保持着密切的学术交流与合作&#xff0c;近一段时间&#xff0c;他又又深入考察了…

jQuery中的事件机制深入浅出

昨天呢,我们大家一起分享了jQuery中的样式选择器,那么今天我们就来看一下jQuery中的事件机制,其实,jQuery中的事件机制与JavaScript中的事件机制区别是不大的,只是,JavaScript中调用是原生的函数方法,而jQuery中调用的绑定的是jQuery中的对象方法,那么在昨天的第一篇中,我们已经…

centos7 安装mysql 解决:Failed to restart mysqld.service: Unit not found

解决方法如下: 首先需要安装mariadb-server~]# yum install -y mariadb-server启动服务~]# systemctl start mariadb.service添加到开机启动~]# systemctl enable mariadb.service安装&#xff1a; yum install -y mariadb-server 成功&#xff01;

重建二叉树

重建二叉树 【题目】&#xff1a; 输入某二叉树的前序遍历和中序遍历的结果&#xff0c;请重建该二叉树&#xff0c;并返回重建后二叉树的根节点。 假设两个遍历的结果中没有重复的数字。 例如&#xff0c;给出 前序遍历 preorder [3,9,20,15,7] 中序遍历 inorder [9,3,15…