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- ...
随机推荐
- JSP路径出现问题
1.错误描述 2.错误原因 <%@ page language="java" import="java.util.*" pageEncoding=&quo ...
- C# Split 根据组合字符进行拆分数组用法
C# Split 根据组合字符进行拆分数组用法,如下代码: string sql = "aaaaaaaaaa{@}bbbbbbbbbb{@}ccccccc#cccccc"; //1 ...
- 小白进阶之Scrapy(基于Scrapy-Redis的分布式以及cookies池)
首先我们更新一下scrapy版本.最新版为1.3 再说一遍Windows的小伙伴儿 pip是装不上Scrapy的.推荐使用anaconda .不然还是老老实实用Linux吧. conda instal ...
- Ajax前后台交互函数
function AJAX(obj){ //做网络请求的时候参数以对象的形式传递进来 //我们规定obj里面包含属性:url, //请求方式type, //date前端给后端传递的参数 //回调函数s ...
- WC2001 高性能计算机
cogs网址 这道题DP 设g[0/1][i][a][b]表示第i个机子做了a个A,b个B,0/1表示当前为A/B的最小代价 N^4转移 设f[i][a][b]表示前i个机子做了a个A,b个B的最小答 ...
- [BZOJ1031] [JSOI2007] 字符加密Cipher (后缀数组)
Description 喜欢钻研问题的JS同学,最近又迷上了对加密方法的思考.一天,他突然想出了一种他认为是终极的加密办法 :把需要加密的信息排成一圈,显然,它们有很多种不同的读法.例如下图,可以读作 ...
- Office 365 Connectors 的使用与自定义开发
前言 我相信很多人都看过<三国演义>,里面有很多引人入胜的故事和栩栩如生的人物,对我而言,曹操手下的一员猛将典韦实在让我印象深刻.例如,书中有一段描写典韦的作战经历: 时西面又急,韦进当之 ...
- 【linux之进程管理,系统监控】
一.进程管理 前台进程:一般是指占据着标准输入和/或标准输出的进程后台进程:不占据默认开启的进程都是前台进程ctrl+C 中断ctrl+z 从前台转入后台bg 后台进程编号 让其在后台运行ls -R ...
- hbase 导入导出、hbase shell 基本命令。
数据导入 ./hbase org.apache.hadoop.hbase.mapreduce.Driver import 表名 数据文件位置hdfs数据文件位置 可以加 前缀 file:/// ...
- js中url跳转问题
问题描述:列表中有不同的企业名字,每个企业名字都有一个不同的链接,用id做为参数区分.点击不同的名字,根据id的不同跳转到对应的详情页,设置连接如下: 1. url = http://localhos ...