After the 10/28 lecture
This commit is contained in:
		
							parent
							
								
									3fbf3eb87c
								
							
						
					
					
						commit
						c565f04461
					
				
					 15 changed files with 228 additions and 15 deletions
				
			
		
							
								
								
									
										32
									
								
								bigos/lecture20251028/function1/milesPerGallon04a.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								bigos/lecture20251028/function1/milesPerGallon04a.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,32 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
# Program: milesPerGallon01.py
 | 
			
		||||
# Objective: Calculate the milage for a vehicle using the fill-up data.
 | 
			
		||||
# Revisions
 | 
			
		||||
#           Check for division by zero error
 | 
			
		||||
# Edward Bigos
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def getFloatValue(message):
 | 
			
		||||
    try:
 | 
			
		||||
        fValue = float(input(message + ": "))
 | 
			
		||||
    except ValueError as error:
 | 
			
		||||
        print("Error: ", error)
 | 
			
		||||
        print("You have entered an invalid value. The input must be a number.")
 | 
			
		||||
        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: ")
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    milesPerGallon = miles/gallons
 | 
			
		||||
except ZeroDivisionError as error:
 | 
			
		||||
    print("Error: ",error)
 | 
			
		||||
    print("You have entered an invalid value for the gallons. The input must greater than zero.")
 | 
			
		||||
    sys.exit(-1)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
print(f"The miles per gallon is {milesPerGallon:.1f}")
 | 
			
		||||
							
								
								
									
										26
									
								
								bigos/lecture20251028/function1/rectangle-area06-function.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								bigos/lecture20251028/function1/rectangle-area06-function.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,26 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
# Program: rectangle-area06.py
 | 
			
		||||
# Objective: Calculate the area of a rectangle. Check for numeric error on length.
 | 
			
		||||
# Revisions
 | 
			
		||||
#           Specify the type of the error as ValueError and print the error type.
 | 
			
		||||
#           Added same to width.
 | 
			
		||||
#           Moved input code to function
 | 
			
		||||
# Edward Bigos
 | 
			
		||||
 | 
			
		||||
def getFloatValue(message):
 | 
			
		||||
    try:
 | 
			
		||||
        fValue = float(input(message + ": "))
 | 
			
		||||
    except ValueError as error:
 | 
			
		||||
        print("Error: ",error)
 | 
			
		||||
        print("You have entered an invalid value. The input must be a number.")
 | 
			
		||||
        sys.exit(-1)
 | 
			
		||||
    return fValue
 | 
			
		||||
 | 
			
		||||
length = getFloatValue("Enter a value for length")
 | 
			
		||||
width  = getFloatValue("Enter a value for width ")
 | 
			
		||||
 | 
			
		||||
area = length * width
 | 
			
		||||
 | 
			
		||||
print(f"The area of the rectangle is {area:.1f}")
 | 
			
		||||
| 
						 | 
				
			
			@ -1,8 +1,8 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
# Program: milesPerGallon04.py
 | 
			
		||||
# Objective: Calculate the milage at fill-up.
 | 
			
		||||
# Program: rectangle-area06.py
 | 
			
		||||
# Objective: Calculate the area of a rectangle. Check for numeric error on length.
 | 
			
		||||
# Revisions
 | 
			
		||||
#           Specify the type of the error as ValueError and print the error type.
 | 
			
		||||
#           Added same to width.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										29
									
								
								bigos/lecture20251028/function1/rectangle-volume2.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								bigos/lecture20251028/function1/rectangle-volume2.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,29 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
# Program: rectangle-volume.py
 | 
			
		||||
# Objective: Calculate the volume of a rectanglar solid. Check for numeric error on length.
 | 
			
		||||
# Revisions
 | 
			
		||||
#           Specify the type of the error as ValueError and print the error type.
 | 
			
		||||
#           Added same to width.
 | 
			
		||||
# Edward Bigos
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def getFloatValue(message):
 | 
			
		||||
    try:
 | 
			
		||||
        fValue = float(input(message + " "))
 | 
			
		||||
    except ValueError as error:
 | 
			
		||||
        print("Error: ",error)
 | 
			
		||||
        print("You have entered an invalid value. The input must be a number.")
 | 
			
		||||
        sys.exit(-1)
 | 
			
		||||
    return fValue
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
length = getFloatValue("Enter a value for length   ")
 | 
			
		||||
width  =  getFloatValue("Enter a value for width   ")
 | 
			
		||||
height =  getFloatValue("Enter a value for height  ")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
area = length * width * height
 | 
			
		||||
 | 
			
		||||
print(f"The volume of the rectanglar solid is {area:.1f}")
 | 
			
		||||
| 
						 | 
				
			
			@ -28,6 +28,7 @@ def getFloatValue(message):
 | 
			
		|||
    return fValue
 | 
			
		||||
 | 
			
		||||
for fillup in fillupList:
 | 
			
		||||
#    print("This fillup data ",fillup)
 | 
			
		||||
    miles = fillup[0]
 | 
			
		||||
    gallons = fillup[1]
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										37
									
								
								bigos/lecture20251028/list01/milesPerGallon05.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								bigos/lecture20251028/list01/milesPerGallon05.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,37 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
# 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],[290,18],[300,16]]
 | 
			
		||||
 | 
			
		||||
def calculateMilesPerGallon(miles,gallons):
 | 
			
		||||
    try:
 | 
			
		||||
        milesPerGallon = miles / gallons
 | 
			
		||||
    except ZeroDivisionError as error:
 | 
			
		||||
        print("Error: ", error)
 | 
			
		||||
        print("You have entered an invalid value for the gallons. The input must greater than zero.")
 | 
			
		||||
        sys.exit(-1)
 | 
			
		||||
    return milesPerGallon
 | 
			
		||||
 | 
			
		||||
def getFloatValue(message):
 | 
			
		||||
    try:
 | 
			
		||||
        fValue = float(input(message + ": "))
 | 
			
		||||
    except ValueError as error:
 | 
			
		||||
        print("Error: ", error)
 | 
			
		||||
        print("You have entered an invalid value. The input must be a number.")
 | 
			
		||||
        sys.exit(-1)
 | 
			
		||||
    return fValue
 | 
			
		||||
 | 
			
		||||
for fillup in fillupList:
 | 
			
		||||
#    print("This fillup data ",fillup)
 | 
			
		||||
    miles = fillup[0]
 | 
			
		||||
    gallons = fillup[1]
 | 
			
		||||
 | 
			
		||||
    milesPerGallon = calculateMilesPerGallon(miles,gallons)
 | 
			
		||||
    print(f"Miles = {miles}, Gallons = {gallons}")
 | 
			
		||||
    print(f"The miles per gallon is {milesPerGallon:.1f}\n")
 | 
			
		||||
							
								
								
									
										39
									
								
								bigos/lecture20251028/list01/milesPerGallon06.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								bigos/lecture20251028/list01/milesPerGallon06.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,39 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
# 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],[290,18],[300,16]]
 | 
			
		||||
 | 
			
		||||
def calculateMilesPerGallon(miles,gallons):
 | 
			
		||||
    try:
 | 
			
		||||
        milesPerGallon = miles / gallons
 | 
			
		||||
    except ZeroDivisionError as error:
 | 
			
		||||
        print("Error: ", error)
 | 
			
		||||
        print("You have entered an invalid value for the gallons. The input must greater than zero.")
 | 
			
		||||
        sys.exit(-1)
 | 
			
		||||
    return milesPerGallon
 | 
			
		||||
 | 
			
		||||
def getFloatValue(message):
 | 
			
		||||
    try:
 | 
			
		||||
        fValue = float(input(message + ": "))
 | 
			
		||||
    except ValueError as error:
 | 
			
		||||
        print("Error: ", error)
 | 
			
		||||
        print("You have entered an invalid value. The input must be a number.")
 | 
			
		||||
        sys.exit(-1)
 | 
			
		||||
    return fValue
 | 
			
		||||
 | 
			
		||||
print("")
 | 
			
		||||
print("       Miles Gallons Miles/Gallon")
 | 
			
		||||
 | 
			
		||||
for fillup in fillupList:
 | 
			
		||||
#    print("This fillup data ",fillup)
 | 
			
		||||
    miles = fillup[0]
 | 
			
		||||
    gallons = fillup[1]
 | 
			
		||||
 | 
			
		||||
    milesPerGallon = calculateMilesPerGallon(miles,gallons)
 | 
			
		||||
    print(f"{miles:10} {gallons:6} {milesPerGallon:10.1f}")
 | 
			
		||||
| 
						 | 
				
			
			@ -22,6 +22,11 @@ except ValueError as error:
 | 
			
		|||
    print("You have entered an invalid value. The input must be a number.")
 | 
			
		||||
    sys.exit(-1)
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    milesPerGallon = miles/gallons
 | 
			
		||||
except ZeroDivisionError as error:
 | 
			
		||||
    print("Error: ", error)
 | 
			
		||||
    print("The number of gallons must be greater than zero.")
 | 
			
		||||
    sys.exit(-2)
 | 
			
		||||
 | 
			
		||||
print(f"The miles per gallon is {milesPerGallon:.1f}")
 | 
			
		||||
| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
 | 
			
		||||
# Program: reactangle-area01.py
 | 
			
		||||
# Program: rectangle-area01.py
 | 
			
		||||
# Objective: Calculate the area of a rectangle. No error checking.
 | 
			
		||||
# Edward Bigos
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
# Program: reactangle-area02.py
 | 
			
		||||
# Program: rectangle-area02.py
 | 
			
		||||
# Objective: Calculate the area of a rectangle. Check for numeric error on length.
 | 
			
		||||
#           No error checking on width yet.
 | 
			
		||||
# Edward Bigos
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,10 +1,10 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
# Program: reactangle-area03.py
 | 
			
		||||
# Program: rectangle-area03.py
 | 
			
		||||
# Objective: Calculate the area of a rectangle. Check for numeric error on length.
 | 
			
		||||
#           Specify the type of the error as ValueError
 | 
			
		||||
#           No error checking on width yet.
 | 
			
		||||
#           Added error checking for width.
 | 
			
		||||
# Edward Bigos
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
| 
						 | 
				
			
			@ -13,8 +13,12 @@ except ValueError:
 | 
			
		|||
    print("You have entered an invalid value. The input must be a number.")
 | 
			
		||||
    sys.exit(-1)
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    width = input("Enter a value for width ")
 | 
			
		||||
    width = float(width)
 | 
			
		||||
except ValueError:
 | 
			
		||||
    print("You have entered an invalid value. The input must be a number.")
 | 
			
		||||
    sys.exit(-1)
 | 
			
		||||
 | 
			
		||||
area = length * width
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,10 +1,10 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
# Program: reactangle-area04.py
 | 
			
		||||
# Program: rectangle-area04.py
 | 
			
		||||
# Objective: Calculate the area of a rectangle. Check for numeric error on length.
 | 
			
		||||
#           Specify the type of the error as ValueError and print the error type.
 | 
			
		||||
#           No error checking on width yet.
 | 
			
		||||
#           Added error checking for width.
 | 
			
		||||
# Edward Bigos
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
| 
						 | 
				
			
			@ -14,8 +14,12 @@ except ValueError as error:
 | 
			
		|||
    print("You have entered an invalid value. The input must be a number.")
 | 
			
		||||
    sys.exit(-1)
 | 
			
		||||
 | 
			
		||||
width = input("Enter a value for width ")
 | 
			
		||||
width = float(width)
 | 
			
		||||
try:
 | 
			
		||||
    width = float(input("Enter a value for width "))
 | 
			
		||||
except ValueError:
 | 
			
		||||
    print("You have entered an invalid value. The input must be a number.")
 | 
			
		||||
    sys.exit(-1)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
area = length * width
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
# Program: reactangle-area05.py
 | 
			
		||||
# Program: rectangle-area05.py
 | 
			
		||||
# Objective: Calculate the area of a rectangle. Check for numeric error on length.
 | 
			
		||||
# Revisions
 | 
			
		||||
#           Specify the type of the error as ValueError and print the error type.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										36
									
								
								bigos/lecture20251028/try1/rectangle-volume.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								bigos/lecture20251028/try1/rectangle-volume.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,36 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
# Program: rectangle-volume.py
 | 
			
		||||
# Objective: Calculate the volume of a rectanglar solid. Check for numeric error on length.
 | 
			
		||||
# Revisions
 | 
			
		||||
#           Specify the type of the error as ValueError and print the error type.
 | 
			
		||||
#           Added same to width.
 | 
			
		||||
# Edward Bigos
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    length = float(input("Enter a value for length "))
 | 
			
		||||
except ValueError as error:
 | 
			
		||||
    print("Error: ",error)
 | 
			
		||||
    print("You have entered an invalid value. The input must be a number.")
 | 
			
		||||
    sys.exit(-1)
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    width = input("Enter a value for width ")
 | 
			
		||||
    width = float(width)
 | 
			
		||||
except ValueError as error:
 | 
			
		||||
    print("Error: ",error)
 | 
			
		||||
    print("You have entered an invalid value. The input must be a number.")
 | 
			
		||||
    sys.exit(-1)
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    height = input("Enter a value for height ")
 | 
			
		||||
    height = float(height)
 | 
			
		||||
except ValueError as error:
 | 
			
		||||
    print("Error: ",error)
 | 
			
		||||
    print("You have entered an invalid value. The input must be a number.")
 | 
			
		||||
    sys.exit(-1)
 | 
			
		||||
 | 
			
		||||
area = length * width * height
 | 
			
		||||
 | 
			
		||||
print(f"The volume of the rectanglar solid is {area:.1f}")
 | 
			
		||||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
#!/usr/bin/python3
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
# Program: reactangle-area06.py
 | 
			
		||||
# Program: Based on rectangle-area06a.py
 | 
			
		||||
# Objective: Calculate the area of a rectangle. Check for numeric error on length.
 | 
			
		||||
# Revisions
 | 
			
		||||
#           Specify the type of the error as ValueError and print the error type.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue