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. java.io.FileNotFoundException: /opt/apache-tomcat-7.0.57/conf/server.xml (权限不够)

    1 错误描述 youhaidong@youhaidong:~$ cd /opt/apache-tomcat-7.0.57 youhaidong@youhaidong:/opt/apache-tomca ...

  2. 完美的js运动框架

    //完美运动框架, 对象,json,函数function move(obj,json,funEnd){clearInterval(obj.timer);//清除定时器obj.timer= setInt ...

  3. python爬虫--爬取某网站电影信息并写入mysql数据库

    书接上文,前文最后提到将爬取的电影信息写入数据库,以方便查看,今天就具体实现. 首先还是上代码: # -*- coding:utf-8 -*- import requests import re im ...

  4. java自带的类压缩和下载,以及递归删除动态的文件(shiro项目中来的十)

    详见项目,不用借助于任何外在的jar包,通过jre自带的实现.

  5. C#图解教程 第二十三章 预处理指令

    预处理指令 什么是预处理指令基本规则#define和#undef指令条件编译条件编译结构诊断指令行号指令区域指令#pragma warning 指令 预处理指令 什么是预处理指令 源代码指定了程序的定 ...

  6. PyTorch官方中文文档:自动求导机制

    自动求导机制 本说明将概述Autograd如何工作并记录操作.了解这些并不是绝对必要的,但我们建议您熟悉它,因为它将帮助您编写更高效,更简洁的程序,并可帮助您进行调试. 从后向中排除子图 每个变量都有 ...

  7. Python基础__函数

    本节将进入函数的介绍,函数是Python基础中最精彩的部分之一,接下来将对函数做详细介绍.函数 函数就是对代码进行一个封装.把实现某一功能的代码进行封装到一起.下次需要使用时不需要进行编写代码直接调用 ...

  8. 【BZOJ2431】逆序对数列(动态规划)

    [BZOJ2431]逆序对数列(动态规划) 题面 Description 对于一个数列{ai},如果有i<j且ai>aj,那么我们称ai与aj为一对逆序对数.若对于任意一个由1~n自然数组 ...

  9. python-kafka实现produce与consumer

    1.python-kafka: api送上:https://kafka-python.readthedocs.io/en/latest/apidoc/KafkaConsumer.html 2.实现一个 ...

  10. libpqxx接口的在linux下的使用,解决psql:connections on Unix domain socket "/tmp/.s.PGSQL.5432"错误

    在项目中使用postgresql数据库时要求在windows和linux双平台兼容.于是在windows下使用的接口在linux下爆出异常: psql:connections on Unix doma ...