Added Homework 04 - Strings

This commit is contained in:
Edward Bigos 2026-11-03 10:54:55 -05:00
commit be356ccb59
24 changed files with 315 additions and 0 deletions

View file

@ -0,0 +1,15 @@
import math
variable = math.pi
print(f"Using Numeric {variable = }")
print(f"|{variable:25}|")
print(f"|{variable:<25}|")
print(f"|{variable:>25}|")
print(f"|{variable:^25}|\n")
variable = "Python 3.9"
print(f"Using String {variable = }")
print(f"|{variable:25}|")
print(f"|{variable:<25}|")
print(f"|{variable:>25}|")
print(f"|{variable:^25}|")

View file

@ -0,0 +1,13 @@
import math
variable = math.pi
print(f"Using String {variable = }")
print(f"|{variable:=<25}|")
print(f"|{variable:=>25}|")
print(f"|{variable:=^25}|\n")
variable = "Python 3.9"
print(f"Using String {variable = }")
print(f"|{variable:=<25}|")
print(f"|{variable:=>25}|")
print(f"|{variable:=^25}|")

View file

@ -0,0 +1,14 @@
import math
variable = 10
print(f"Using Numeric {variable = }")
print(f"This prints without formatting {variable}")
print(f"This prints with formatting {variable:d}")
print(f"This prints also with formatting {variable:n}")
print(f"This prints with spacing {variable:10d}\n")
variable = math.pi
print(f"Using Numeric {variable = }")
print(f"This prints without formatting {variable}")
print(f"This prints with formatting {variable:f}")
print(f"This prints with spacing {variable:20f}")

View file

@ -0,0 +1,11 @@
variable = 1200356.8796
print(f"Using Numeric {variable = }")
print(f"With two decimal places: {variable:.2f}")
print(f"With four decimal places: {variable:.3f}")
print(f"With two decimal places and a comma: {variable:,.2f}")
print(f"With a forced plus sign: {variable:+.2f}\n")
variable *= -1
print(f"Using Numeric {variable = }")
print(f"With two decimal places and a comma: {variable:,.2f}")

View file

@ -0,0 +1,4 @@
print(f'Number\t\tSquare\t\tCube')
for x in range(1, 11):
print(f'{x:2d}\t\t\t{x*x:3d}\t\t\t{x*x*x:4d}')

View file

@ -0,0 +1,5 @@
print(f'Number\t\tSquare\t\t\tCube')
for x in range(1, 11):
x = float(x)
print(f'{x:5.2f}\t\t{x*x:6.2f}\t\t{x*x*x:8.2f}')

View file

@ -0,0 +1,22 @@
APPLES = .50
BREAD = 1.50
CHEESE = 2.25
numApples = 3
numBread = 10
numCheese = 6
prcApples = numApples * APPLES
prcBread = numBread* BREAD
prcCheese = numCheese * CHEESE
strApples = 'Apples'
strBread = 'Rye Bread'
strCheese = 'Cheese'
total = prcBread + prcCheese + prcApples
print(f'{"My Grocery List":^30s}')
print(f'{"="*30}')
print(f'{strApples:10s}{numApples:10d}\t${prcApples:>5.2f}')
print(f'{strBread:10s}{numBread:10d}\t${prcBread:>5.2f}')
print(f'{strCheese:10s}{numCheese:10d}\t${prcCheese:>5.2f}')
print(f'{"Total:":>20s}\t${total:>5.2f}')

View file

@ -0,0 +1,9 @@
import math
goldenRatio = (1+math.sqrt(5))/2
print(f"{goldenRatio=}")
print("\n")
print(f"{goldenRatio = :.6f}")
print(f"{(1+math.sqrt(5))/2 = :.6f}")

View file

@ -0,0 +1,7 @@
val1 = float(input("Enter a value for val1 "))
val2 = float(input("Enter a value for val2 "))
# using the addition operator
res = val1 + val2
print("The sum is ",res)