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. linq使用日记

    //普通查询 var query = (from t in ServiceList                                  where t.CreateUserID == A ...

  2. iOS - XMPP 的使用

    1.XMPP XMPP 是一个基于 Socket 通信的即时通讯的协议,它规范了即时通信在网络上数据的传输格式,比如登录,获取好友列表等等的格式.XMPP 在网络传输的数据是 XML 格式. 开发架构 ...

  3. EntityFramework Core 2.0 Explicitly Compiled Query(显式编译查询)

    前言 EntityFramework Core 2.0引入了显式编译查询,在查询数据时预先编译好LINQ查询便于在请求数据时能够立即响应.显式编译查询提供了高可用场景,通过使用显式编译的查询可以提高查 ...

  4. JavaScript设计模式(7)-设配器模式

    适配器模式 1. 作用: 协调两个不同的接口 2. 适用场景 适配器适用于客户期待的接口与现有 API 提供的接口不兼容这种场景.他只能用来协调语法上的差异问题.适配器所适配的两个方法执行的应该是类似 ...

  5. Xcode 9.0 新增功能大全

    Xcode是用于为Apple TV,Apple Watch,iPad,iPhone和Mac创建应用程序的完整开发人员工具集.Xcode开发环境采用tvOS SDK,watchOS SDK,iOS SD ...

  6. springmvc后台取值中文乱码问题

    字符-->字节.字节-->字符时需要用到编码(Encoder).解码(Decoder) 几种编码: ASCII:总共128 ISO-8859-1:涵盖大部分西欧语言字符.一个字符一个字节表 ...

  7. 总结各类错误(always online)

    最近发现打暴力(还有梦想中的正解)都会打错,决定好好总结一下各种坑比错误QAQ 1.一定要好好看数据范围,接近int类型上限,如果要求和,一定要开long long并且改大你的inf值(TAT暴力分流 ...

  8. [HDU5663]Hillan and the girl

    题面戳我(题面很鬼畜建议阅读一下) 题意:给出n,m,求 \[\sum_{i=1}^{n}\sum_{j=1}^{m}[gcd(i,j)\mbox{不是完全平方数}]\] 多组数据,\(n,m\le1 ...

  9. (2)Deep Learning之线性单元和梯度下降

    往期回顾 在上一篇文章中,我们已经学会了编写一个简单的感知器,并用它来实现一个线性分类器.你应该还记得用来训练感知器的『感知器规则』.然而,我们并没有关心这个规则是怎么得到的.本文通过介绍另外一种『感 ...

  10. XeLaTeX中文模板

    XeLaTeX对中文的支持很友好,可以直接调用系统已安装字体进行文档的撰写.其中需要引用字体的名字,开始遇到了写问题,经常发现字体未引用,现在大概明白了. 引用字体的时候,如果不加中括号,就需要引用字 ...