有点懵
num = input("请输入你的分数:")num1 = int(num)
A = isinstance(num1, int)
while A == True:
if 0 <= num1 < 60:
print("D")
elif 60 <= num1 < 80:
print("C")
elif 80 <= num1 < 90:
print("B")
elif 90 <= num1 <100:
print("A")
elif num1 == 100:
print("S")
else:
print("请输入有效分数")
num = input("请输入你的分数:")
num1 = int(num) #这行报错
A = isinstance(num1, int)
if A == False:
if num == e:
print("")
else:
print("格式错误")
python第二版 006的动手题,因为之前自己学过一点点(真的只是一点点)但是又忘了,重新巩固
自己给自己加了点难度,假如别人输入的不是数字而是别的,想着判断出来然后分情况输出,但是自己卡在num = int(num)这了,假如别人输入的是英文,该怎么解决
各位大佬指点下,有啥错误说啥,思路错了提醒下啦!谢谢 本帖最后由 qq1151985918 于 2022-8-21 23:28 编辑
第2.3.4行
num.isdigit()
当 num 全部为数字时返回 True 否则返回 False
num = input("请输入你的分数:")
while not num.isdigit():
print("**输入错误,请输入数字!")
num = input("请输入你的分数:")
num1 = int(num)
A = isinstance(num1, int)
while A == True:
if 0 <= num1 < 60:
print("D")
elif 60 <= num1 < 80:
print("C")
elif 80 <= num1 < 90:
print("B")
elif 90 <= num1 <100:
print("A")
elif num1 == 100:
print("S")
else:
print("请输入有效分数")
num = input("请输入你的分数:")
num1 = int(num) #这行报错
A = isinstance(num1, int)
if A == False:
if num == e:
print("")
else:
print("格式错误")
num1 = int(num) #这行报错 , num你输入非数字肯定会报错。
num.isdigit()判断下字符串是不是由数字组成,然后在int(num)就行了 用num.isdigit判断一下是否为数字,不是数字直接赋值一个大于100的数,在后面判断时自会让重新输入
num = input("请输入你的分数:")
if not num.isdigit():
num=101
num1 = int(num)
A = isinstance(num1, int)
while A == True:
if 0 <= num1 < 60:
print("D")
elif 60 <= num1 < 80:
print("C")
elif 80 <= num1 < 90:
print("B")
elif 90 <= num1 <100:
print("A")
elif num1 == 100:
print("S")
else:
print("请输入有效分数")
num = input("请输入你的分数:")
if not num.isdigit():
num=101
num1 = int(num) #这行报错
A = isinstance(num1, int)
if A == False:
if num == e:
print("")
else:
print("格式错误")
{:10_254:} 本帖最后由 asky533 于 2022-8-23 22:46 编辑
num = input("请输入你的分数:")
A = isinstance(num, int)
while A == True:
if 0 <= num1 < 60:
print("D")
elif 60 <= num1 < 80:
print("C")
elif 80 <= num1 < 90:
print("B")
elif 90 <= num1 <100:
print("A")
elif num1 == 100:
print("S")
else:
print("请输入有效分数")
num = input("请输入你的分数:")
页:
[1]