Python报错TypeError: '<' not supported between instances of 'str' and 'int'
n = input()
if n>=100:print(int(n)/10)
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型即可。
n = input()
n = int(n)
if n>=100:print(int(n)/10)
else:print(int(n)*10)
或者
n = int(input("Input a number:"))
if n>=100:print(int(n)/10)
else:print(int(n)*10)
Python报错TypeError: '<' not supported between instances of 'str' and 'int'的更多相关文章
- python报错:not supported between instances of 'str' and 'int'
not supported between instances of 'str' and 'int' : 意思就是字符串不能和int类型的数值比较
- input()报错:TypeError: '>=' not supported between instances of 'str' and 'int'
今天学习python基础—分支与循环,接触到了if.在练习一个if语句的时候,出现了错误. 题目是: 根据分数划分成四个级别:优秀.良好.及格.不及格,分数是72: grade = 72if grad ...
- TypeError: '<' not supported between instances of 'str' and 'int'
<不支持str实例和int实例之间的对比 birth是str类型 2000是int类型 所以无法对比,报错 birth = input('birth: ') if birth < 2000 ...
- python的强制转换(当出现 not supported between instances of 'str' and 'int' 的错误时)
当我们编程时,有时会出现如下错误:TypeError: '>' not supported between instances of 'str' and 'int' 如下图: 这是因为input ...
- python报错 TypeError: a() got multiple values for argument 'name'
[问题现象] 在一次调用修饰函数中出现了问题,折腾了一下午,一直报错 TypeError: got multiple values for argument 只是很简单的调用 from tsu2Ru ...
- python pip install 报错TypeError: unsupported operand type(s) for -=: 'Retry' and 'int' Command "python setup.py egg_info" failed with error code 1 in
pip install http://download.pytorch.org/whl/cu80/torch-0.2.0.post3-cp27-cp27mu-manylinux1_x86_64.whl ...
- python 报错TypeError: 'range' object does not support item assignment,解决方法
贴问题 nums = range(5)#range is a built-in function that creates a list of integers print(nums)#prints ...
- python报错 TypeError: string indices must be integers
所以在读取字典的时候,最好先判断类型,然后再查看它是否已经有这样的属性: type(mydict) == type({}) #检查不是字典 如果是字典,再看看有没有这样的属性: ...
- 解决pip安装时出现报错TypeError unsupported operand type(s) for -= 'Retry' and 'int'
1.参考 https://stackoverflow.com/questions/42610545/typeerror-unsupported-operand-types-for-retry-and- ...
随机推荐
- 校园网IPv6加速
对于广大学生来说,上网是一件很纠结的事情,校园网要么按时间计费,要么按流量计费,要么是校园宽带.按时间计费速度慢,按流量计费费用高,校园宽带还不能共享,只能电脑开热点给手机上网.有没有既能提高网速又经 ...
- java暴力递归回溯算法
今天这个问题是我之前一直想解决的,还记得以前第一次上蓝桥杯的课的时候,也就是大一高数期中模拟考试那天,下午去上蓝桥杯课,遇到这道题,当时写了写,根本没有思路,然后就给大一的模拟考试去了.印象深刻啊,一 ...
- 动态链接库(DLL)
DLL 的类型 当您在应用程序中加载 DLL 时,可以使用两种链接方法来调用导出的 DLL 函数.这两种链接方法是加载时动态链接和运行时动态链接. 加载时动态链接 在加载时动态链接中,应用程序像调用本 ...
- php 数组排序得方法
$sort1 = array_column($list_bloc[1], 'value');//按照$list_bloc[1]里面的value做降序排序 array_multisort($sort1, ...
- Gulp-自动化编译sass和pug文件
突然发现在我博客文章中,缺少这一块的记录,那我就补一篇吧. gulp的环境配置和安装:http://www.cnblogs.com/padding1015/p/7162024.html 这里就补充一篇 ...
- angular中label包含input点击事件的问题
问题:当点击input时,input不能勾选,单label内的其他区域点击均可控制input勾选. 分析:点击input时,$event.target.tagName //INPUT, 点击img ...
- 关于win8/win8.1系统不能调节亮度的解决办法
有时候我们重装了win8系统之后开始可以调节亮度,但是再重新安装了显卡驱动之后发现不能调节亮度了,解决办法就是添加一项注册表. 下载地址:http://7xnarc.com1.z0.glb.cloud ...
- 读取超大Excel(39万行数据)
有个学长需要处理Excel数据,Excel数据共有39W,将数据读取后处理并导出数据.最开始尝试了 NPOI ,发现NPOI 并不能完成该项任务,随后尝试引用的com组件:Microsoft.Offi ...
- delphi简单的分页实现(高手可以不看)
适合初学者,练习几个控件的使用 1.先放一张界面控件布局: 4个button,2个label,1个edit,1个TRzsplitter(把界面分割成上下2部分),1一个adoquery,1个adoco ...
- 《深入理解Bootstrap》读书笔记(一)
栅格系统 实现原理 通过定义容器大小,平分12份,再调整内外边距,最后结合媒体查询. 通过一系列包含内容的行和列来创建页面布局.下面列出了 Bootstrap 栅格系统是如何工作的: 1.行必须放置在 ...