python - Letters Breaking Code -
in need code,
print("please enter number plate") num_plate = (input()) #asks , stores number plate print ("please enter distance") dist = (float(input())) #asks , stores distance print ("please enter speed limit") speed_lim = (float(input())) #asks , stores speed limit print ("please enter finish time") end = (float(input())) #asks , stores end time whenever input letters comes error:
traceback (most recent call last): file "\average speed camera code.py", line 17, in <module> dist = (float(input())) valueerror: not convert string float: 'fg'
i think you're getting @ you'd rather code didn't crash on invalid input? you'll need error handling. if want force valid input like:
print ("please enter distance") while true: try: dist = (float(input())) break except valueerror: print("please enter valid input!") if feeling flash wrap in re-usable function reduce repetition other calls.
Comments
Post a Comment