【发布时间】:2021-01-23 10:59:59
【问题描述】:
如何修复这个我可以输入浮点数的代码
x = 0
y = x
count = 0
while True:
x = input("please enter student's grade: ")
if x == "quit" or x == "exit":
break
if x.isdigit():
x = float(x)
if (x >= 0) and (x <= 20):
y += x
count += 1
z = y / count
print(f"your students average grade is {z}")
else:
print("please enter a number between 0 and 20")
else:
print("input must be number")
当我输入浮点数时,我得到“输入必须是数字”
【问题讨论】:
-
这是因为浮点输入,即:
3.0不被视为完全数字,因为它包含. -
这能回答你的问题吗? Using isdigit for floats?
标签: python python-3.x python-2.7 python-requests