【发布时间】:2013-11-13 06:01:36
【问题描述】:
我只是被这段代码弄糊涂了:
print("Welcome to Healthometer, powered by Python...")
miles = input("How many miles can you walk?: ")
if float(miles) <= 0:
print("Who do you think you are?!! Go and walk 1000 miles now!")
elif float(miles) >= 10:
print("You are very healthy! Keep it up!")
elif float(miles) > 0 and miles < 10:
print("Good. Try doing 10 miles")
else:
print("Please type in a number!")
miles = float(input("How many miles can you walk?: "))
if miles <= 0:
print("Who do you think you are?!! Go and walk 1000 miles now!")
elif miles >= 10:
print("You are very healthy! Keep it up!")
elif miles > 0 and miles < 10:
print("Good. Try doing 10 miles")
但是,看看错误: http://i.stack.imgur.com/PYT80.png
有人告诉我在 Python 中尝试 try/except,但在查看文档后,我不知道该做什么以及如何使用代码中的所有其他 if 和 elif 来实现它。 我试过这样做:
print("Welcome to Healthometer, powered by Python...")
try:
miles = float(input("How many miles can you walk? "))
except ValueError:
print("That is not a valid number of miles")
if float(miles) <= 0:
print("Who do you think you are?!! Go and walk 1000 miles now!")
elif float(miles) >= 10:
print("You are very healthy! Keep it up!")
elif float(miles) > 0 and miles < 10:
print("Good. Try doing 10 miles")
else:
print("Please type in a number!")
miles = float(input("How many miles can you walk?: "))
if miles <= 0:
print("Who do you think you are?!! Go and walk 1000 miles now!")
elif miles >= 10:
print("You are very healthy! Keep it up!")
elif miles > 0 and miles < 10:
print("Good. Try doing 10 miles")
但它给出了:第 7 行,在 如果浮动(英里)
我正在使用 Python 3.3.2
【问题讨论】:
-
你刚刚发布了这个问题,他们确实告诉你如何使用它。 stackoverflow.com/questions/19736589/…
-
是的,他们做到了,但不知道如何在代码中实现它!
-
当我将它放入代码时,我遇到了一大堆错误。
-
你得到这个“这不是一个有效的里程数”对吗?
-
@jeremynealbrown:请您将其写为答案并给出更正的代码。非常感谢!
标签: python-3.x