Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that accepts a date as month/day/year, verifies that it is a val

ID: 3660144 • Letter: W

Question

Write a program that accepts a date as month/day/year, verifies that it is a valid date (e.g. 5/24/2012 is valid but 9/31/2012 is not because September has only 30 days), and then calculates the corresponding day number. Second part of the assignment is: Write a program that computes the fuel efficiency of a multi-leg journey. The program will first prompt for the starting odometer reading and then get information about a series of legs. For each leg, the user enters the current odometer reading and the amount of gas used (separated by a comma). The user signals the end of the trip with a blank line. The program should print out the miles per gallon achieved on each leg and the total MPG for the trip. Part Three: Modify the econd program to get its input from a file.

Explanation / Answer

def main(): stmi = input("Please enter the starting odometer reading: ") tgas = 0.0 if stmi != "": legmi, gas = input("Please enter the leg miles and the gas (leg miles,gas) or press enter for total miles per gallon: ") if legmi != "": dist = legmi - stmi lmpg = dist/gas while legmi != "": tgas = tgas + gas print ("The miles per gallon of the leg is ", lmpg) stmi = legmi legmi, gas = input("Please enter the leg miles and the gas (leg miles,gas) or press enter for total miles per gallon: ") else: tmpg = (legmi - stmi)/tgas print ("The total miles per gallon is ", tmpg) main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote