In: Computer Science
Many exercise apps record both the time and the distance a user covers while walking, running, biking, or swimming. Some users of the apps want to know their average pace in minutes and seconds per mile, while others want to know their average speed in miles per hour. In many cases, we are interested in projected time over a specific distance. For example, if I run 6.3 miles in 53 minutes and 30 seconds, my average pace is 8 minutes and 29 seconds per mile, my average speed is 7.07 miles per hour and my projected time for 2.7 miles is 22 minutes and 55 seconds. Your job in Part 2 of this homework is to write a program that asks the user for the minutes, seconds, miles run, and miles to target from an exercise event and outputs both the average pace and the average speed. You can expect minutes and seconds to both be integers, but miles will be a float. All minutes and seconds must be maintained as integers so please use integer division and modulo operations. Note that if you have a float value then the function int gives you the integer value.
For example:
>>> x = 29.52
>>> y = int(x)
>>> print(y) 29
The output for the speed will be a float and should be printed to 2 decimal places. Notice also that our solution generates a blank line before the output of calculations.
miles = float(input('Enter the miles you have run for: ')) mins = int(input('Enter the minutes you have run for: ')) seconds = int(input('Enter the seconds you have run for: ')) milesTargetted = float(input('Enter the miles you are targetting for: ')) totalTimeInSecs = mins * 60 + seconds avgPaceInSecs = int(totalTimeInSecs / miles) print("Averaeg pace is %d minutes and %d seconds per mile" % (avgPaceInSecs // 60, avgPaceInSecs % 60)) avgSpeed = (miles * 3600) / (totalTimeInSecs) print("Averaeg speed is %.2f miles per hour" % (avgSpeed)) projectedTimeInSecs = milesTargetted * totalTimeInSecs / miles print("Projected time for %.2f miles is %d minutes and %d seconds" % (milesTargetted, projectedTimeInSecs // 60, projectedTimeInSecs % 60))
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.