Question

In: Computer Science

Python While traveling home for the holiday, you wondered how much time you'd save if you...

Python

While traveling home for the holiday, you wondered how much time you'd save if you drove faster. The distance home is 120 miles, and you decided to compare driving 55 mph versus 70 mph. You also wondered if driving faster around town really saves you that much time. The around-town distance you chose was 5 miles, using speeds of 25 and 35 mph. Of course, you decided that no amount of times savings is worth the risk to yourself or others, but you still wanted to find the answer.

Create two functions to help calculate the travel time in hours, minutes and seconds and to display the results.

# Calculate travel time in minutes given the distance in miles and the speed in mph
calc_travel_time ( distance, speed )

# Output the travel time hours, minutes and seconds given distance and speed
print_travel_time ( distance, speed )

Your Python solution must include the following:

  • The calc_travel_time() function will return the travel time in minutes
  • The print_travel_time() function will use (call) the calc_travel_time() function, and will determine the actual time in hours, minutes and seconds, using the int() and round() Python functions
  • Include the single line comment above each function
  • Comment the test section of your program
  • Include the standard class ''' comment section at the top of your file
  • Include a section called References that lists the web site reference link

Tip:

Expected output:

To travel 120 miles at 55 MPH will take 2 hr, 10 min and 55 sec
To travel 120 miles at 70 MPH will take 1 hr, 42 min and 51 sec
To travel 5 miles at 25 MPH will take 0 hr, 12 min and 0 sec
To travel 5 miles at 35 MPH will take 0 hr, 8 min and 34 sec

Solutions

Expert Solution

Given below is the code for the question. Ensure to indent as shown in image. Please do rate the answer if it helped. Thank you

# Calculate travel time in minutes given the distance in miles and the speed in mph
def calc_travel_time( distance, speed ):
   t = distance/speed
   t = t * 60 #convert to minutes
   return t

# Output the travel time hours, minutes and seconds given distance and speed
def print_travel_time( distance, speed ):
   t = calc_travel_time(distance, speed)
   mins = int(t)
   secs = int(round(60*(t - mins), 0))
   hours = mins // 60
   mins = mins % 60
   print('To travel {} miles at {} MPH will take {} hr, {} min and {} sec'.format(distance, speed, hours, mins, secs))

print_travel_time(120, 55)
print_travel_time(120, 70)
print_travel_time(5, 25)
print_travel_time(5, 35)


Related Solutions

If the time value of the money is .10 how much do you have to save...
If the time value of the money is .10 how much do you have to save per year for 20 years to have $50,000 per year for perpetuity? Assume that the first deposit is immediate and that the first payment will be at the beginning of the 21st year. Suppose that you decide to hold the bonds in the previous question for a year, and then sell them. The next year, the interest rate on comparable bonds increases to 9.5%....
You are trying to decide how much to save for retirement. Assume you plan to save...
You are trying to decide how much to save for retirement. Assume you plan to save $8,000 per year with the first investment made one year from now. You think you can earn 5.5​% per year on your investments and you plan to retire in 32 ​years, immediately after making your last $8,000 investment. a. How much will you have in your retirement account on the day you​ retire? b.​ If, instead of investing $8,000 per​ year, you wanted to...
You are trying to decide how much to save for retirement. Assume you plan to save...
You are trying to decide how much to save for retirement. Assume you plan to save $ 6,500 per year with the first investment made one year from now. You think you can earn 5.0​% per year on your investments and you plan to retire in 36 ​years, immediately after making your last $ 6,500 investment. a. How much will you have in your retirement account on the day you​ retire? b.​ If, instead of investing $ 6,500 per​ year,...
You are trying to decide how much to save for retirement. Assume you plan to save...
You are trying to decide how much to save for retirement. Assume you plan to save $5,000 per year with the first investment made one year from now. You think you can earn 10.0​% per year on your investments and you plan to retire in   43 ​years, immediately after making your last $5,000 investment. a. How much will you have in your retirement account on the day you​ retire? b.​ If, instead of investing $5,000 per​ year, you wanted to...
You are trying to decide how much to save for retirement. Assume you plan to save...
You are trying to decide how much to save for retirement. Assume you plan to save $6,000 per year with the first investment made one year from now. You think you can earn ​10.0% per year on your investments and you plan to retire in 34 ​years, immediately after making your last $6,000 investment. a. How much will you have in your retirement account on the day you​ retire? b.​ If, instead of investing $6,000 per​ year, you wanted to...
You are trying to decide how much to save for retirement. Assume you plan to save...
You are trying to decide how much to save for retirement. Assume you plan to save $5,000 per year with the first investment made one year from now. You think you can earn 10.5​% per year on your investments and you plan to retire in 31 ​years, immediately after making your last $5,000 investment. a. How much will you have in your retirement account on the day you​ retire? b.​ If, instead of investing $5,000 per​ year, you wanted to...
You are trying to decide how much to save for retirement. Assume you plan to save...
You are trying to decide how much to save for retirement. Assume you plan to save $5,000 per year with the first investment made one year from now. You think you can earn 10.5​% per year on your investments and you plan to retire in 31 ​years, immediately after making your last $5,000 investment. a. How much will you have in your retirement account on the day you​ retire? b.​ If, instead of investing $5,000 per​ year, you wanted to...
You are trying to decide how much to save for retirement. Assume you plan to save...
You are trying to decide how much to save for retirement. Assume you plan to save $4,500 per year with the first investment made one year from now. You think you can earn 5.5​% per year on your investments and you plan to retire in 26 ​years, immediately after making your last $4,500 investment. a. How much will you have in your retirement account on the day you​ retire? b.​ If, instead of investingv$4,500 per​ year, you wanted to make...
You are trying to decide how much to save for retirement. Assume you plan to save...
You are trying to decide how much to save for retirement. Assume you plan to save $8,000 per year with the first investment made one year from now. You think you can earn 8.0​% per year on your investments and you plan to retire in 37 ​years, immediately after making your last $8,000 investment. a. How much will you have in your retirement account on the day you​ retire? b.​ If, instead of investing $8,000 per​ year, you wanted to...
You are trying to decide how much to save for retirement. Assume you plan to save...
You are trying to decide how much to save for retirement. Assume you plan to save $5,000 per year with the first investment made one year from now. You think you can earn 10% per year on your investments and you plan to retire in 43 years, immediately after making your last $5,000 investment. If, instead of investing $5,000 per year, you wanted to make one lump-sum investment today for your retirement that will result in the same retirement saving,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT