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'的更多相关文章

  1. python报错:not supported between instances of 'str' and 'int'

    not supported between instances of 'str' and 'int' : 意思就是字符串不能和int类型的数值比较

  2. input()报错:TypeError: '>=' not supported between instances of 'str' and 'int'

    今天学习python基础—分支与循环,接触到了if.在练习一个if语句的时候,出现了错误. 题目是: 根据分数划分成四个级别:优秀.良好.及格.不及格,分数是72: grade = 72if grad ...

  3. TypeError: '<' not supported between instances of 'str' and 'int'

    <不支持str实例和int实例之间的对比 birth是str类型 2000是int类型 所以无法对比,报错 birth = input('birth: ') if birth < 2000 ...

  4. python的强制转换(当出现 not supported between instances of 'str' and 'int' 的错误时)

    当我们编程时,有时会出现如下错误:TypeError: '>' not supported between instances of 'str' and 'int' 如下图: 这是因为input ...

  5. python报错 TypeError: a() got multiple values for argument 'name'

    [问题现象] 在一次调用修饰函数中出现了问题,折腾了一下午,一直报错 TypeError:  got multiple values for argument 只是很简单的调用 from tsu2Ru ...

  6. 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 ...

  7. 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 ...

  8. python报错 TypeError: string indices must be integers

    所以在读取字典的时候,最好先判断类型,然后再查看它是否已经有这样的属性: type(mydict) == type({})             #检查不是字典 如果是字典,再看看有没有这样的属性: ...

  9. 解决pip安装时出现报错TypeError unsupported operand type(s) for -= 'Retry' and 'int'

    1.参考 https://stackoverflow.com/questions/42610545/typeerror-unsupported-operand-types-for-retry-and- ...

随机推荐

  1. Linux显示隐藏文件

    Linux显示隐藏文件 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ ls -a . .dbus .local .xsession-errors.old .. ...

  2. 异常-----Can't convert the date to string, because it is not known which parts of the date variable are in use. Use ?date, ?time or ?datetime built-in, or ?string.\u003Cformat> or ?string(format) built-

    1.错误描述 五月 27, 2014 12:07:05 上午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template proc ...

  3. Linux之批量挂载硬盘

    ############parted工具分区############### #!/bin/bash #shell脚本开头格式PATH=/bin:/sbin:/usr/bin:/usr/sbin #保证 ...

  4. 【BZOJ1997】Planar(2-sat)

    [BZOJ1997]Planar(2-sat) 题面 BZOJ 题解 很久没做过\(2-sat\)了 今天一见,很果断的就来切 这题不难呀 但是有个玄学问题: 平面图的性质:边数\(m\)的最大值为\ ...

  5. [luogu3600]随机数生成器

    题面在这里 题意 给定n个[1-x]的随机整数\(a_1,a_2,a_3,...,a_n\)和q个询问区间\((l_i,r_i)\), 求出\(\max_{i=1}^{q}({\min_{j=l_i} ...

  6. HDU4812

    树分治 求逆元请递推,不然会TLE 开桶记录即可 注意常数 # pragma comment(linker,"/STACK:102400000,102400000") # incl ...

  7. [BZOJ1606] [Usaco2008 Dec] Hay For Sale 购买干草 (dp)

    Description 约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单位的马车,去顿因家买一些干草.  顿因有H(1≤H≤5000)包干草,每 ...

  8. js去重合并

    1.去重 for(var q = 0;q<jsonArr.length;q++){   for(var e=0;e<jsonArr[q].data.length;e++){   var m ...

  9. postgresql搭建从库

    postgresql搭建从库 master  10.40.196.27 slave   10.40.55.69 需求:master和slave作为主从流复制,当master宕机后,slave切换为新主 ...

  10. enable_shared_from_this类的作用和实现

    使用举例 实际中, 经常需要在一个被shared_ptr管理的对象的内部获取自己的shared_ptr. 比如: 通过this指针来构造一个shared_ptr, 如下: struct Bad { v ...