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
|
||||
import sys
|
||||
|
||||
# Program: reactangle-area06.py
|
||||
# Objective: Calculate the area of a rectangle. Check for numeric error on length.
|
||||
# Program: milesPerGallon04.py
|
||||
# Objective: Calculate the milage at fill-up.
|
||||
# Revisions
|
||||
# Specify the type of the error as ValueError and print the error type.
|
||||
# Added same to width.
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
#!/usr/bin/python3
|
||||
import sys
|
||||
|
||||
# Program: milesPerGallon01.py
|
||||
# Program: milesPerGallon04.py
|
||||
# Objective: Calculate the milage for a vehicle using the fill-up data.
|
||||
# Revisions
|
||||
# Check for division by zero error
|
||||
# Edward Bigos
|
||||
|
||||
fillupList = [[200,10],[400,19], [190,9.8]]
|
||||
|
||||
def calculateMilesPerGallon(miles,gallons):
|
||||
try:
|
||||
milesPerGallon = miles / gallons
|
||||
|
|
@ -25,11 +27,9 @@ def getFloatValue(message):
|
|||
sys.exit(-1)
|
||||
return fValue
|
||||
|
||||
|
||||
|
||||
miles = getFloatValue("Enter a number of miles traveled")
|
||||
gallons = getFloatValue("Enter the number of gallons on the last fill-up")
|
||||
for fillup in fillupList:
|
||||
miles = fillup[0]
|
||||
gallons = fillup[1]
|
||||
|
||||
milesPerGallon = calculateMilesPerGallon(miles,gallons)
|
||||
|
||||
print(f"The miles per gallon is {milesPerGallon:.1f}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue