Question: # ! / usr / bin / env python 3 from datetime import date print ( Today ' s date:, date.today ( ) )
#usrbinenv python
from datetime import date
printTodays date:", date.today
printSamuel Oh
# I state the code submitted is my own work.
printThe Miles Per Gallon Program'
# A while loop which allows the user to enter multiple times
while True:
# Asking for information & then validating
# If not valid, asking again
# Get input for miles driven
milesDriven floatinput
Enter miles driven:
# Validate miles driven must be nonnegative
while milesDriven :
printInvalid Entry'
milesDriven floatinputEnter miles driven:
# Get input for gallons of gas used
numberOfGallons floatinputEnter gallons of gas used:
# Validate gallons of gas used must be nonnegative
while numberOfGallons :
printInvalid Entry'
numberOfGallons floatinputEnter gallons of gas used:
# Get input for cost per gallon
costPerGallon floatinputEnter cost per gallon:
# Validate cost per gallon must be nonnegative
while costPerGallon :
printInvalid Entry'
costPerGallon floatinputEnter cost per gallon:
# Calculating and displaying results on screen
# Calculate miles per gallon
milesPerGallon milesDriven numberOfGallons
# Calculate total gas cost
totalGasCost numberOfGallons costPerGallon
# Calculate cost per mile
costPerMile totalGasCost milesDriven
# Display results with formatting
print
Miles Per Gallon: f milesPerGallon
printTotal Gas Cost: $f totalGasCost
printCost Per Mile: $f costPerMile
# Ask if the user wants to enter another trip
opt input
Get entries for another trip yn
# If the user does not want to repeat, exit the loop
if opt n or opt N:
break
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
