鱼C论坛

 找回密码
 立即注册
查看: 2255|回复: 4

Python字符类型不一致报错

[复制链接]
发表于 2022-7-23 15:46:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
想请教下这个是什么原因引起的报错,要怎么解决

score = input("ni de fen shu: ")
socre = int(score)

if 0 <= score < 60:
    print('D')
elif 60 <= score < 80:
    print('C')
elif 80 <= score < 90:
    print('B')
elif 90 <= score < 100:
    print('A')


ni de fen shu: 79
Traceback (most recent call last):
  File "C:/Users/Administrator/Desktop/test01.py", line 4, in <module>
    if 0 <= score < 60:
TypeError: '<=' not supported between instances of 'int' and 'str'
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-7-23 15:54:20 | 显示全部楼层
score = input("ni de fen shu: ")
socre = int(score)

if 0 <= socre < 60:
    print('D')
elif 60 <= socre < 80:
    print('C')
elif 80 <= socre < 90:
    print('B')
elif 90 <= socre < 100:
    print('A')
鹅,变量不要设容易混淆的,前面为socre = int(score),后面成了score了……
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2022-7-23 15:55:45 | 显示全部楼层
score = int(input("enter score: "))

if score > 100 or score < 0:
    print('你可能输入了一个来着火星的成绩 %s' %score)
elif score >= 90:
    print('A')
elif score >= 80:
    print('B')
elif score >= 60:
    print('C')
else:
    print('D')
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-7-23 16:02:04 | 显示全部楼层
裂开了,变量名被我写错了。。。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-7-23 16:19:06 | 显示全部楼层
WJM_CSU 发表于 2022-7-23 16:02
裂开了,变量名被我写错了。。。

正确的英文是 score
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-28 12:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表