请大神们帮我看一下什么问题?
print("请输入您的成绩:")temp = input()
score = int(temp)
while score.isdigit() == False :
print("非法操作,请输入一个数字:\n")
temp = input()
score = int(temp)
if score > 90 :
print("您的成绩为A")
if 80 < score <= 90 :
print("您的成绩为B")
if 60 < score <= 80 :
print("您的成绩为C")
if score < 60 :
print("您的成绩为D")
Traceback (most recent call last):
File "C:/Users/Administrator/Desktop/python练习题/成绩小程序.py", line 5, in <module>
while score.isdigit() == False :
AttributeError: 'int' object has no attribute 'isdigit' 本帖最后由 liuzhengyuan 于 2020-4-21 18:51 编辑
isdigit() 只支持字符串(str),你的 score 是整形(int),当然不行
temp 是字符串(str),把 score.isdigit() 改为 temp.isdigit(),即可
还有,你要先判断他是不是数字,然后在变成数字
print("请输入您的成绩:")
temp = input()
while temp.isdigit() == False :
print("非法操作,请输入一个数字:\n")
temp = input()
score = int(temp)
score = int(temp)
if score > 90 :
print("您的成绩为A")
if 80 < score <= 90 :
print("您的成绩为B")
if 60 < score <= 80 :
print("您的成绩为C")
if score < 60 :
print("您的成绩为D") 就是整型变量没有'isdigit'这个函数,你的score都已经是整型了,还用判断他是数字吗?
非要改,直接用temp.isdigit()
页:
[1]