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. ubuntu14.04 64位 安装Tomcat

    ubuntu14.04 64位 安装Tomcat 1 下载Tomcat 在htt://www.tomcat.apache.org官网上下载apache-tomcat-7.0.57.tar.gz 2 解 ...

  2. iOS - GATT Profile 简介

    1.引言 现在低功耗蓝牙(BLE)连接都是建立在 GATT (Generic Attribute Profile) 协议之上.GATT 是一个在蓝牙连接之上的发送和接收很短的数据段的通用规范,这些很短 ...

  3. 升级adb注意事项

    最近使用adb devices老提示设备offline,百度试了好多方法都不行,后面才发现是因为没有把adb文件的名称中含有adb的所有文件复制到 c:/windows/system目录,复制完后只记 ...

  4. SpringMVC 框架系列之初识与入门实例

    微信公众号:compassblog 欢迎关注.转发,互相学习,共同进步! 有任何问题,请后台留言联系! 1.SpringMVC 概述 (1). MVC:Model-View-Control Contr ...

  5. JQuery实现点击按钮切换图片(附源码)--JQuery基础

    JQuery实现切换图片相对比较简单,直接贴代码了哈,有注释噢!疑问请追加评论哈,不足之处还请大佬们指出! 1.案例代码: demo.html: <!DOCTYPE html><ht ...

  6. 洛谷P3402 【模板】可持久化并查集(可持久化线段树,线段树)

    orz TPLY 巨佬,题解讲的挺好的. 这里重点梳理一下思路,做一个小小的补充吧. 写可持久化线段树,叶子节点维护每个位置的fa,利用每次只更新一个节点的特性,每次插入\(logN\)个节点,这一部 ...

  7. Emacs考场配置

    当年\(NOip\)考场配置不记得啦 存在这里搞事情 (set-background-color "gray15") (set-foreground-color "gra ...

  8. 【洛谷1131】【ZJOI2007】时态同步

    题面 题目描述 小Q在电子工艺实习课上学习焊接电路板.一块电路板由若干个元件组成,我们不妨称之为节点,并将其用数字1,2,3-.进行标号.电路板的各个节点由若干不相交的导线相连接,且对于电路板的任何两 ...

  9. enable_shared_from_this类的作用和实现

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

  10. [解决]Linux Tomcat启动慢--Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [236,325] milliseconds

    一.背景 今天部署项目到tomcat,执行./startup.sh命令之后,访问项目迟迟加载不出来,查看日志又没报错(其实是我粗心了,当时tomcat日志还没打印完),一开始怀疑是阿里云主机出现问题, ...