Python字符类型不一致报错
想请教下这个是什么原因引起的报错,要怎么解决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' 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了……{:10_261:} 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') 裂开了,变量名被我写错了。。。 WJM_CSU 发表于 2022-7-23 16:02
裂开了,变量名被我写错了。。。
正确的英文是 score
页:
[1]