python
score = int(input("请输入成绩:"))if 90 <= score <= 100:
print("A")
elif 80 <= score < 90:
print("B")
elif 60 <= score < 80:
print("C")
elif score < 60:
print("D")
else:
print("输入格式错误")
这个输入小数为什么会错误呢我输入100.0的话 int不是应该自动转化为整数100吗 因为你输入的100.0 这个字符串 里有点,所以不能转化为整数,应该用float(input("输入的成绩:")) int不能将带小数的字符串转换为整数
你可以试试 int('1.2')
解决方法是,用么用float,要么只在整数情况下转换
temp = input("请输入成绩:")
if temp.isdigit():
score = int(temp) Mr.Lo 发表于 2017-12-4 15:32
因为你输入的100.0 这个字符串 里有点,所以不能转化为整数,应该用float(input("输入的成绩:"))
懂了 谢谢 BngThea 发表于 2017-12-4 15:59
int不能将带小数的字符串转换为整数
你可以试试 int('1.2')
懂了 谢谢
页:
[1]