今天学习python基础—分支与循环,接触到了if。在练习一个if语句的时候,出现了错误。

题目是: 根据分数划分成四个级别:优秀、良好、及格、不及格,分数是72:

grade = 72
if grade >= 90:
print('优秀')
elif grade >=70:
print('良好')
elif grade >=60:
print('及格')
else:
print('不及格')
 
这种情况下没有报错,打印出:良好。
    然后我就想换一种方法,把前几天学到的input也用进去,根据输入的成绩来判断分数属于哪个级别,代码如下:
grade = input('请输入你的分数:')
if grade >= 90:
print('优秀')
elif grade >=70:
print('良好')
elif grade >=60:
print('及格')
else:
print('不及格')
当我输入分数为85时,报错:TypeError: '>=' not supported between instances of 'str' and 'int'

报错原因是:input()输入的内容是一个字符串,字符串跟整型数值进行比较,类型不匹配

修改方法:

grade = int(input('请输入你的分数:'))

input()报错:TypeError: '>=' not supported between instances of 'str' and 'int'的更多相关文章

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

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

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

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

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

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

  7. PyCharm启动报错 TypeError: unsupported operand type(s) for /: ‘str’ and ‘str’ 解决

    这个提示大概是说:"类型错误:不支持操作类型为字符串和字符串",直接把两个字符串(BASE_DIR = os.path.dirname(os.path.dirname(os.pat ...

  8. firefox浏览器中使用vux的x-input报错TypeError: _this3.$refs.input.scrollIntoViewIfNeeded is not a function

    最近做公众号项目,想着统一风格,所以决定使用vux. 在调试时发现,只要鼠标点击x-input输入框,就会报错 TypeError: _this3.$refs.input.scrollIntoView ...

  9. [转载]UEditor报错TypeError: me.body is undefined

    本文转载来自:UEditor报错TypeError: me.body is undefined 今天在使用UEditor的setContent的时候报错,报错代码如下 TypeError: me.bo ...

随机推荐

  1. 砍树,POJ(2665)

    题目链接:http://poj.org/problem?id=2665 解题报告: 这里的区域没有重复,若有重复的话,模拟即可. #include <cstdio> #include &l ...

  2. DOM节点(二):操作节点

    appendChild() 用于向childNodes列表的末尾添加一个节点. var returnedNode = someNode.appendChild(newNode); 如果传入的节点已经是 ...

  3. innerHTML动态添加标签的注意事项

    在使用javascript动态添加页面上元素时,我们经常会使用DOM去逐个地将节点添加到文档碎片中,再将整个文档节点添加到DOM树中.其实还有一种方法动态添加元素:innerHTML. 我最近要将一大 ...

  4. 第9章 初识HAL固件库

    本章参考资料:<STM32F76xxx参考手册>.<STM32F7xx规格书>.<Cortex-M3权威指南>, STM32 HAL库帮助文档:<STM32F ...

  5. 4、SpringBoot------邮件发送(2)

    开发工具:STS 代码下载链接:https://github.com/theIndoorTrain/Springboot/tree/0d6194d6ea2d7f4e19791a3d3f3167f861 ...

  6. 实例:关于ALV控件可编辑的整理

    使ALV控件中的内容可编辑 这应该是一个非常有用的功能,这样我们便可以用它来代替table control来编出一些有这现成功能的界面来.实际上,让alv中的内容可以被编辑与alv的事件无关.但是经常 ...

  7. SpringMVC系列一

    首先介绍一下SpringMVC的执行流程:如图 1.用户在客户端发送请求,经过前端控制器DispatcherServlet,请求处理器处理,返回ModelAndView返回结果到前端控制器: 2.前端 ...

  8. java 二进制、位运算、和移位运算符(2013-07-30-bd 写的日志迁移

    二进制是逢2进位的进位制,0.1是基本算符, 1字节=8位 比如 int a =1 ;int 占4个字节在计算机里表示为: java中的4个位运算,分别是“按位与&.按位或|.按位异或^,按位 ...

  9. Python中的not, and, or

    logical_operator_lst = [ ('and 与运算',), ('or 或运算',), ('not 非运算',), ('逻辑运算符的优先级',), ('实例',), ('练习',), ...

  10. Visual Stutio 2015激活密钥

    Visual Stutio 2015 专业版激活密钥:HMGNV-WCYXV-X7G9W-YCX63-B98R2 Visual Stutio 2015 企业版激活密钥:HM6NR-QXX7C-DFW2 ...