Question: # ! / usr / bin / env python 3 from datetime import date print ( Today ' s date:, date.today ( ) )

#!/usr/bin/env python3
from datetime import date
print("Today's date:", date.today())
print("Samuel Oh")
# I state the code submitted is my own work.
print('The 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 = float(input('
Enter miles driven: '))
# Validate miles driven (must be non-negative)
while milesDriven <0:
print('Invalid Entry')
milesDriven = float(input('Enter miles driven: '))
# Get input for gallons of gas used
numberOfGallons = float(input('Enter gallons of gas used: '))
# Validate gallons of gas used (must be non-negative)
while numberOfGallons <0:
print('Invalid Entry')
numberOfGallons = float(input('Enter gallons of gas used: '))
# Get input for cost per gallon
costPerGallon = float(input('Enter cost per gallon: '))
# Validate cost per gallon (must be non-negative)
while costPerGallon <0:
print('Invalid Entry')
costPerGallon = float(input('Enter 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: %.2f'% milesPerGallon)
print('Total Gas Cost: $%.1f'% totalGasCost)
print('Cost Per Mile: $%.1f'% costPerMile)
# Ask if the user wants to enter another trip
opt = input('
Get entries for another trip (y/n)?')
# 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!