Instructions: You should submit your answer to this question as a Python code
with .py extension to the corresponding question in Google Classroom.
Attention: Make sure to write your name, surname, and student ID number.
Question:
(Average speed) Assume a runner runs 14 kilometers in 45 minutes and 30 sec-
onds. Write a program that displays the average speed in miles per hour. (Note that
1 mile is 1.6 kilometers.)
SOLUTION TO THE ABOVE QUESTION
SOLUTION CODE
#A ruuner runs 14 km in 45 minutes 30 seconds
#45 minutes 30 seconds is equal to 45.5minutes and 1 mile is equal to 1.6 kilometers
total_distance_in_km = 14
time_in_minutes = 45.5;
#Now lets convert 14 kilometers to miles
total_distance_in_miles = total_distance_in_km/1.6
#45.5 minutes == 45.5/60 hours
time_in_hours = (45.5/60)
#lets clculate the avreage speed in miles per hour
average_speed_in_miles_per_hour = total_distance_in_miles/time_in_hours;
#format the average speed in miles per hour to 4 decimal places
average_speed_in_miles_per_hour = float("{0:.4f}".format(average_speed_in_miles_per_hour))
#Now print the runnes average speed in miles
print("\nThe runners average speed in miles per hour = "+str(average_speed_in_miles_per_hour))
SAMPLE PROGRAM OUTPUT
Comments
Leave a comment