the title say it all, i tried doing this:
import random
speed = float(input("Which was the speed of the vehicle in that moment? "))
trafficTicket = 0
if speed == "":
print("The speed was not informed. ")
randomNumber = random.randint(1, 120)
RandomTrafficTicketValue = randomNumber * 7
print(f"O value of the traffic ticket in this situation is going to be {RandomTrafficTicketValue} dollars. ")
if speed < 30:
print("The vehicle's speed is very low, tell the driver to change hands. ")
if speed > 90:
trafficTicketValue = speed - 90
print(f"Due to speed above the permitted speed, the driver must receive a trafficTicket worth {trafficTicketValue * 7} dollars. ")
but got this error: ValueError: could not convert string to float: ''
Any way to go around it, so i can make a if statement when the user dont type anything?
i tried finding a solution based in what i needed but only found a question involving python made in 2010, and that dont are especially what im trying to find
>Solution :
Accept the input as a plain string and check if it is empty before you call float():
speed = input("what was your speed? ")
# if they actually typed something, convert it to a float
if speed:
speed = float(speed)
# now handle the various speed values
else:
print("You did not enter anything")