今天学习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. 【转】android中的Style与Theme

    Android默认情况下提供了一些实用的主题样式,比如说Theme.Dialog可以让你的Activity变成一个窗口风格,而Theme.Light则让你的整个Activity具有白色的背景,而不是黑 ...

  2. 2017.11.12 web中JDBC 方式访问数据库的技术

    JavaWeb------ 第四章 JDBC数据库访问技术 在JavaWeb应用程序中数据库访问是通过Java数据库连接(JavaDateBase Connectivity简称JDBC)数据库的链接一 ...

  3. Docker 入门教程与实践

    title: Docker 入门教程与实践 tags: Docker ---- 在Windows上安装Docker客户端 1.下载Docker TollBox: https://docs.docker ...

  4. 安装juicer

    由于我第一次安装 JUICER时遇到了很多问题,现在把这些问题都记录下来,给同样第一次安装使用的同学一点借鉴. 前面已经安装了Torch3和Tracter,这都是为安装Juicer做的准备,现在安装J ...

  5. e.preventdefault() 别滥用

    有的时候我们会为事件回调函数添加一个参数(通常是e),并在函数中加入e.preventdefault():以取消默认行为.由于习惯,我顺手将它写到了一个checkbox的change事件中.由于不同的 ...

  6. SpringMVC3中返回json字符串时500 Internal Server Error的处理方案

    搭建 Spring3+MyBatis+Rest+BootStrap+JBPM项目环境后,测试发现了一个操蛋的问题.使用Spring MVC的自动类型转换为JSON时,后台数据List/Map获取完全正 ...

  7. 通过ServletContext取Spring的WebApplicationContext

    当 Web 应用集成 Spring 容器后,代表 Spring 容器的 WebApplicationContext 对象将以WebApplicationContext.ROOT_WEB_APPLICA ...

  8. 控制元素的div属性

    1.需求分析 改变元素的宽.高.颜色.显示.重置等属性. 2.技术分析 基础的css.html.js 3.详细分析 如图,单击按钮,改变元素属性: 3.1 HTML部分 根据视图不难发现,内容分两大不 ...

  9. vue-wechat-title

    html中的title安装:npm install vue-wechat-title --save1.在mian.js中//网页titleimport VueTitle from 'vue-wecha ...

  10. 知识总结和记录——HTML

    文档结构 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="U ...