Write a Python program to determine if a car is moving at a safe speed using distance and time.
Ask the user for the car’s name and store it in a variable called car_name
.
Ask for the distance the car traveled (in meters) and store it in a variable called distance
(as a float).
Ask for the time taken (in seconds) and store it in a variable called time
(as a float).
Calculate the speed using the formula:
speed = distance / time
Use an if-elif-else
structure to classify the car’s speed:
"Warning, [car_name]! Your speed is [speed] m/s, which is too fast!"
"Caution, [car_name]! Your speed is [speed] m/s. Drive carefully!"
"Safe, [car_name]! Your speed is [speed] m/s. You are driving safely."
"Error: Time cannot be zero. Please check the input values for [car_name]."
We’re always looking for international STEM educators to join our team. If you are interested, please send us a mail and we’ll get back to you!
If you have any questions, kindly send us a mail. Don’t forget to follow and like all our social accounts to get updates on competitions!