I got a value error and even if I try playing around with the code, it doesn\'t work!
How can I get it right? - I am using Python 3.3.2!
Here is the code:
The problem is exactly what the Traceback log says: Could not convert string to float
The way most people would approach this problem is with a try/except (see here), or using the isdigit() function (see here).
Try/Except
try:
miles = float(input("How many miles can you walk?: "))
except:
print("Please type in a number!")
Isdigit()
miles = input("How many miles can you walk?: ")
if not miles.isdigit():
print("Please type a number!")
Note that the latter will still return false if there are decimal points in the string
Okay, I won't be able to get back to you for a while, so I'll post the answer just in case.
while True:
try:
miles = float(input("How many miles can you walk?: "))
break
except:
print("Please type in a number!")
#All of the ifs and stuff
The code's really simple: