今天学习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. 问题 C: P4 游戏中的Human角色

    题目描述 在一个平面打斗游戏中,任何的角色(Role)都有血量(blood)和位置loc(此处loc是Location类的实例)属性.有了Role类,可以派生出不同的角色,如人.神仙.怪兽等.如下程序 ...

  2. Flashing Fluorescents(状压DP)

    Flashing Fluorescents 时间限制: 1 Sec  内存限制: 128 MB提交: 56  解决: 19[提交] [状态] [讨论版] [命题人:admin] 题目描述 You ha ...

  3. mac jdk profile 永久的配置

    配置java_home 在MAC中设置JAVA_HOME环境变量 环境变量要再etc目录下的profile文件中配置,这样才是永久的配置. cd /etc vi profile 按 i 键进入写模式 ...

  4. Python 3 collections.defaultdict() 与 dict的使用和区别

    综述: 这里的defaultdict(function_factory)构建的是一个类似dictionary的对象,其中keys的值,自行确定赋值,但是values的类型,是function_fact ...

  5. 缓冲区溢出实战教程系列(三):利用OllyDbg了解程序运行机制

    想要进行缓冲区溢出的分析与利用,当然就要懂得程序运行的机制.今天我们就用动态分析神器ollydbg来了解一下在windows下程序是如何运行的. 戳这里看之前发布的文章: 缓冲区溢出实战教程系列(一) ...

  6. 第10章 新建工程-库函数版—零死角玩转STM32-F429系列

    第10章     新建工程—库函数版 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/fire ...

  7. AngularJS 重复HTML元素

    data-ng-repeat指令会重复一个HTML元素 <!DOCTYPE html><html><head><meta http-equiv="C ...

  8. c++谭浩强教材教学练习例题1.2 求两数之和 为什么sum=a+b;sum的值为65538

    第一章 #include <iostream>using namespace std; int main(){ int a,b,sum; sum=a+b; cin>>a> ...

  9. 【转载】CString,string,char*之间的转换

    本文转自 <> 这三种类型各有各的优点,比如CString比较灵活,是基于MFC常用的类型,安全性也最高,但可移植性最差.string是使用STL时必不可少的类型,所以是做工程时必须熟练掌 ...

  10. 【yii】【php】自定义故障代码

    实际状态码: 200 操作成功 406 账号密码错误 208 请勿重复操作 401 需登陆验证 405 不容许此方法 409 验证错误