Question: I need to write a program that calculates the time to run a full , half , 10 miles and 5 mile marathons in minutes

I need to write a program that calculates the time to run a full , half , 10 miles and 5 mile marathons in minutes and hours i have the code written but if i enter a speed greater than 5mph it gives a error of 'hours' not defined and will only return a answer for the 5 mile run . i just need to understand why . here's my code . this is in python using the spyder program

# user enters their speed

speed=int(input("enter your speed(mph):"))

# calculate time to run 5 miles

time=(5/speed)*60

#minutes to hours and minutes

if(time<60): print("time to run 5 miles:",int(time),"minutes")

else:

hours=time/60

minutes=time%60

print("time to run 5 miles:",int(hours),"hours",int(minutes),"minutes")

#calc time in minutes to run 10 miles

time=(10/speed)*60

#calc time in minutes to hours and minutes

if(time<60): print("time to run 10 miles:",int(time),"minutes") else: hours=time/60 minutes=time%60 print("time to run 10 miles:",int(hours),"hours",int(minutes) ,"minutes")

#calc time in minutes run half marathon

time=(13.1/speed)*60

# calc in minutes to hours

if(time<60): print("time to run half marathon",int(time),"minutes") else: hours=time/60 minutes=time%60 print("time to run half marathon:",int(hours),"hours",int(minutes) ,"minutes") # minutes to run marathon

time=(26.2/speed)*60

#calc minutes to hours

if(time<60): print("time to run marathon:",int(time),"minutes") else: hours=time/60 minutes=time%60 print("time to run marathon:",int(hours),"hours",int(minutes),"minutes")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!