Lecture 10-28 code additions
This commit is contained in:
parent
12e989631c
commit
3fbf3eb87c
2 changed files with 10 additions and 10 deletions
|
|
@ -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.
|
||||||
|
|
|
||||||
|
|
@ -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]
|
||||||
|
gallons = fillup[1]
|
||||||
|
|
||||||
|
milesPerGallon = calculateMilesPerGallon(miles,gallons)
|
||||||
miles = getFloatValue("Enter a number of miles traveled")
|
print(f"The miles per gallon is {milesPerGallon:.1f}")
|
||||||
gallons = getFloatValue("Enter the number of gallons on the last fill-up")
|
|
||||||
|
|
||||||
milesPerGallon = calculateMilesPerGallon(miles,gallons)
|
|
||||||
|
|
||||||
print(f"The miles per gallon is {milesPerGallon:.1f}")
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue