Lecture 10-28 code
This commit is contained in:
parent
97b81f2b77
commit
12e989631c
11 changed files with 288 additions and 0 deletions
29
bigos/lecture20251028/function1/rectangle-area06.py
Normal file
29
bigos/lecture20251028/function1/rectangle-area06.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/python3
|
||||
import sys
|
||||
|
||||
# Program: reactangle-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
|
||||
|
||||
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)
|
||||
|
||||
area = length * width
|
||||
|
||||
print(f"The area of the rectangle is {area:.1f}")
|
||||
35
bigos/lecture20251028/list01/milesPerGallon04.py
Normal file
35
bigos/lecture20251028/list01/milesPerGallon04.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#!/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 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
|
||||
|
||||
|
||||
|
||||
miles = getFloatValue("Enter a number of miles traveled")
|
||||
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}")
|
||||
27
bigos/lecture20251028/try1/milesPerGallon01.py
Normal file
27
bigos/lecture20251028/try1/milesPerGallon01.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/python3
|
||||
import sys
|
||||
|
||||
# Program: milesPerGallon01.py
|
||||
# Objective: Calculate the milage for a vehicle using the fill-up data.
|
||||
# Revisions
|
||||
# None
|
||||
# Edward Bigos
|
||||
|
||||
|
||||
try:
|
||||
miles = float(input("Enter a number of miles traveled: "))
|
||||
except ValueError as error:
|
||||
print("Error: ",error)
|
||||
print("You have entered an invalid value. The input must be a number.")
|
||||
sys.exit(-1)
|
||||
|
||||
try:
|
||||
gallons = float(input("Enter the number of gallons on the last fill-up: "))
|
||||
except ValueError as error:
|
||||
print("Error: ",error)
|
||||
print("You have entered an invalid value. The input must be a number.")
|
||||
sys.exit(-1)
|
||||
|
||||
milesPerGallon = miles/gallons
|
||||
|
||||
print(f"The miles per gallon is {milesPerGallon:.1f}")
|
||||
32
bigos/lecture20251028/try1/milesPerGallon02.py
Normal file
32
bigos/lecture20251028/try1/milesPerGallon02.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
|
||||
|
||||
|
||||
try:
|
||||
miles = float(input("Enter a number of miles traveled: "))
|
||||
except ValueError as error:
|
||||
print("Error: ",error)
|
||||
print("You have entered an invalid value. The input must be a number.")
|
||||
sys.exit(-1)
|
||||
|
||||
try:
|
||||
gallons = float(input("Enter the number of gallons on the last fill-up: "))
|
||||
except ValueError as error:
|
||||
print("Error: ",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("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}")
|
||||
15
bigos/lecture20251028/try1/rectangle-area01.py
Normal file
15
bigos/lecture20251028/try1/rectangle-area01.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
# Program: reactangle-area01.py
|
||||
# Objective: Calculate the area of a rectangle. No error checking.
|
||||
# Edward Bigos
|
||||
|
||||
length = float(input("Enter a value for length "))
|
||||
|
||||
|
||||
width = input("Enter a value for width ")
|
||||
width = float(width)
|
||||
|
||||
area = length * width
|
||||
|
||||
print(f"The area of the rectangle is {area:.1f}")
|
||||
20
bigos/lecture20251028/try1/rectangle-area02.py
Normal file
20
bigos/lecture20251028/try1/rectangle-area02.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/python3
|
||||
import sys
|
||||
|
||||
# Program: reactangle-area02.py
|
||||
# Objective: Calculate the area of a rectangle. Check for numeric error on length.
|
||||
# No error checking on width yet.
|
||||
# Edward Bigos
|
||||
|
||||
try:
|
||||
length = float(input("Enter a value for length "))
|
||||
except:
|
||||
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)
|
||||
|
||||
area = length * width
|
||||
|
||||
print(f"The area of the rectangle is {area:.1f}")
|
||||
21
bigos/lecture20251028/try1/rectangle-area03.py
Normal file
21
bigos/lecture20251028/try1/rectangle-area03.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/python3
|
||||
import sys
|
||||
|
||||
# Program: reactangle-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.
|
||||
# Edward Bigos
|
||||
|
||||
try:
|
||||
length = float(input("Enter a value for length "))
|
||||
except ValueError:
|
||||
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)
|
||||
|
||||
area = length * width
|
||||
|
||||
print(f"The area of the rectangle is {area:.1f}")
|
||||
22
bigos/lecture20251028/try1/rectangle-area04.py
Normal file
22
bigos/lecture20251028/try1/rectangle-area04.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/python3
|
||||
import sys
|
||||
|
||||
# Program: reactangle-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.
|
||||
# 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)
|
||||
|
||||
width = input("Enter a value for width ")
|
||||
width = float(width)
|
||||
|
||||
area = length * width
|
||||
|
||||
print(f"The area of the rectangle is {area:.1f}")
|
||||
28
bigos/lecture20251028/try1/rectangle-area05.py
Normal file
28
bigos/lecture20251028/try1/rectangle-area05.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/python3
|
||||
import sys
|
||||
|
||||
# Program: reactangle-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.
|
||||
# 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)
|
||||
|
||||
area = length * width
|
||||
|
||||
print(f"The area of the rectangle is {area:.1f}")
|
||||
32
bigos/lecture20251028/try2/milesPerGallon03.py
Normal file
32
bigos/lecture20251028/try2/milesPerGallon03.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
|
||||
|
||||
|
||||
try:
|
||||
miles = float(input("Enter a number of miles traveled: "))
|
||||
except ValueError as error:
|
||||
print("Error: ",error)
|
||||
print("You have entered an invalid value. The input must be a number.")
|
||||
sys.exit(-1)
|
||||
|
||||
try:
|
||||
gallons = float(input("Enter the number of gallons on the last fill-up: "))
|
||||
except ValueError as error:
|
||||
print("Error: ",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("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}")
|
||||
27
bigos/lecture20251028/try2/rectangle-area07.py
Normal file
27
bigos/lecture20251028/try2/rectangle-area07.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/python3
|
||||
import sys
|
||||
|
||||
# Program: reactangle-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 the width")
|
||||
|
||||
area = length * width
|
||||
|
||||
print(f"The area of the rectangle is {area:.1f}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue