执行Python提示《not supported between instances of str and int》
1 n = input()
2 if n>=100:print(int(n)/10)
3 else:print(int(n)*10)
报错内容:
Traceback (most recent call last):File "1.py", line 12, in <module>if n>=100:print(int(n)/10)
TypeError: '>=' not supported between instances of 'str' and 'int'***Repl Closed***
分析:input()返回的数据类型是str,不能直接和整数进行比较,必须先把str换成整数,使用int()方法
因此,将input变量转换为int型即可。
1 n = input()
2 n = int(n)
3 if n>=100:print(int(n)/10)
4 else:print(int(n)*10)
或者:
1 n = int(input("Input a number:"))
2 if n>=100:print(int(n)/10)
3 else:print(int(n)*10)
执行Python提示《not supported between instances of str and int》相关推荐
- ‘<’ not supported between instances of ‘str’ and ‘int’
'<' not supported between instances of 'str' and 'int' python 中 字符串 和 整形 进行比较之后 出现的报错信息. python 中 ...
- 【已解决】TypeError: ‘<‘ not supported between instances of ‘str‘ and ‘int‘_Python系列学习笔记
TypeError: '<' not supported between instances of 'str' and 'int' 翻译:str类型无法与int类型比较 解决:将<两侧类型 ...
- 成功解决TypeError: ‘<‘ not supported between instances of ‘str‘ and ‘int‘
成功解决TypeError: '<' not supported between instances of 'str' and 'int' 目录 解决问题 解决思路 解决方法 解决问题 Type ...
- TypeError: not supported between instances of str and int【python3】
python3报错:TypeError: '>' not supported between instances of 'str' and 'int' **报错原因:**int类型没有转换为st ...
- 提示错误“'=' not supported between instances of 'range' and 'int'”
在学习<Designing Machine Learning Systems with Python>(中文名<机器学习系统设计--python语言实现>)一书中,第三章第二节 ...
- 成功解决极其刁钻bug之TypeError: ‘<=‘ not supported between instances of ‘list‘ and ‘int‘
成功解决极其刁钻bug之TypeError: '<=' not supported between instances of 'list' and 'int' 目录 解决问题 解决思路 解决方法 ...
- not supported between instances of 'SafeText' and 'int' 问题出现以及解决
1.今天更新完代码,突然间报了这个错误:'<' not supported between instances of 'SafeText' and 'int' 2.主要代码如下,其中是最后一行报 ...
- java执行python提示import os找不到_java利用Jython调用python抛出错误ImportError: No module named odbchelper...
Python代码: import odbchelper def add(x, y): """ add method """ return x ...
- python运行报错TypeError: cannot concatenate 'str' and 'int' objects
dict运行报错 d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59 } for key in d: print key+":& ...
最新文章
- html概述和基本结构
- 图文讲解,团队开发中的 Git 最佳实践
- 浅谈Spark应用程序的性能调优
- java如何读取下拉列表的值_java - 如何在Selenium 2中选择/获取下拉选项
- python循环遍历所有目录_python 遍历文件夹
- leetcode 40. 组合总和 II 思考分析
- JavaScript笔记-对wheelDeltaY和deltaY的体会
- BZOJ3376: [Usaco2004 Open]Cube Stacking 方块游戏
- HDU-1159-Common Subsequence
- 学习windows内核一
- virtualbox vm 虚拟机 迁移
- deepstream多路rtsp流,避免相互影响
- python错误提示未定义tn_未找到Python方法,但在类中定义
- 用java模拟csma_CSMA/CD仿真的过程
- VC6.0 快捷键整理
- Excel中怎么把经纬度记录转成经纬度数值形式
- 中国互联网20周年谈----GITC 2014
- 再读德鲁克#2 如何提升生产率
- 干货 | Elasticsearch 8.X 节点角色划分深入详解
- Docker Desktop(WSL2)修改镜像存储位置
热门文章
- H.266之CABAC
- 10--File类字节流异常
- arduino uno r3单片机封装图_Arduino和单片机区别,及Arduino入门教程
- python基础--面向对象(一)
- [转贴]我孙子.........笑死我了
- 给你一个登录页面,你该如何做渗透测试呢?
- pdf文件里面水印如何全部去掉
- pycharm关联github
- 使用JAF创建MIME消息
- 电脑为什么不能运行php文件路径,window_windows系统下英雄联盟不能启动 指定路径不存在的解决办法,小编把英雄联盟从别人电脑里 - phpStudy...