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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started