83.4k views
2 votes
) Write a program to calculate the time to run 5 miles, 10 miles, half marathon, and full marathon if you can run at a constant speed. The distance of a half marathon is 13.1 miles and that of a full marathon is 26.2 miles. Report the time in the format of hours and minutes. Your program will prompt for your running speed (mph) as an integer.

User KDecker
by
3.6k points

1 Answer

9 votes

Answer:

def cal_time(distance, speed):

time = distance / speed

hour = str(time)[0]

minutes = round(float(str(time)[1:]) * 60)

print(f"The time taken to cover {distance}miles is {hour}hours, {minutes}minutes")

miles = [5, 10, 13.1, 26.2]

myspeed = int(input("Enter user speed: "))

for mile in miles:

cal_time(mile, myspeed)

Step-by-step explanation:

The python program prints out the time taken for a runner to cover the list of distances from 5 miles to a full marathon. The program prompts for the speed of the runner and calculates the time with the "cal_time" function.

User Rijk
by
3.2k points