Lecture 10-28 code additions

This commit is contained in:
Edward Bigos 2025-10-28 09:08:08 -04:00
parent 12e989631c
commit 3fbf3eb87c
2 changed files with 10 additions and 10 deletions

View file

@ -1,8 +1,8 @@
#!/usr/bin/python3 #!/usr/bin/python3
import sys import sys
# Program: reactangle-area06.py # Program: milesPerGallon04.py
# Objective: Calculate the area of a rectangle. Check for numeric error on length. # Objective: Calculate the milage at fill-up.
# Revisions # Revisions
# Specify the type of the error as ValueError and print the error type. # Specify the type of the error as ValueError and print the error type.
# Added same to width. # Added same to width.

View file

@ -1,12 +1,14 @@
#!/usr/bin/python3 #!/usr/bin/python3
import sys import sys
# Program: milesPerGallon01.py # Program: milesPerGallon04.py
# Objective: Calculate the milage for a vehicle using the fill-up data. # Objective: Calculate the milage for a vehicle using the fill-up data.
# Revisions # Revisions
# Check for division by zero error # Check for division by zero error
# Edward Bigos # Edward Bigos
fillupList = [[200,10],[400,19], [190,9.8]]
def calculateMilesPerGallon(miles,gallons): def calculateMilesPerGallon(miles,gallons):
try: try:
milesPerGallon = miles / gallons milesPerGallon = miles / gallons
@ -25,11 +27,9 @@ def getFloatValue(message):
sys.exit(-1) sys.exit(-1)
return fValue return fValue
for fillup in fillupList:
miles = fillup[0]
miles = getFloatValue("Enter a number of miles traveled") gallons = fillup[1]
gallons = getFloatValue("Enter the number of gallons on the last fill-up")
milesPerGallon = calculateMilesPerGallon(miles,gallons) milesPerGallon = calculateMilesPerGallon(miles,gallons)
print(f"The miles per gallon is {milesPerGallon:.1f}") print(f"The miles per gallon is {milesPerGallon:.1f}")