Unit 3
Source Code
import time
print("Unit 3 Source Code")
done = False
while not done:
print("Menu System")
choice = input("Choice: ")
match choice:
case "E1":
print("Example 1")
x = 0
while x < 5:
print("Python is my favorite language!")
x += 1
case "E2":
print("Example 2")
# version 1
x = 1
while x <= 5:
print(x)
x += 1
# version 2
print("swapped lines")
x = 1
while x < 6:
print(x)
x += 1
case "E3":
print("Example 3")
# version 1
x = 1
while x < 10:
print(x)
x += 2
# version 2
x = 1
while x < 10:
if x % 2 == 1:
print(x)
x += 1
case "E4":
print("Example 4")
total = 0
x = 1
while x <= 10:
total += x
x += 1
print("Total: " + str(total))
case "E5":
print("Example 5")
x = 0
total = 0
while x < 3:
num = int(input("Number: "))
total += num
x += 1
print("Total: " + str(total))
case "E6":
print("Example 6")
x = 3
while x >= 0:
print(x)
x -= 1
case "E7":
print("Example 7")
myName = input("What's your name? ")
for x in range(5):
print(x, myName)
case "E8":
total = 0
for x in range(3):
num = int(input("Number: "))
total += num
print("Total: " + str(total))
case "E9":
print("Example 9")
for x in range(1, 6):
print(x)
case "E10":
print("Example 10")
print("Number\tSquared")
for x in range(-3, 4):
print(str(x) + "\t" + str(x**2))
case "E11":
print("Example 11")
for x in range(2, 11, 2):
print(x)
case "E12":
print("Example 12")
for x in range(10, -1, -1):
print(x)
case "E13":
score = int(input("Score: "))
while score < 0 or score > 100:
print("error, can't be less than 0")
print("or greater than 100")
score = int(input("Score: "))
else:
print("Valid Score")
case "E14":
print("Example 14")
while ((score := int(input("Score: "))) < 0 or score > 100):
print("error, can't be less than 0")
print("or greater than 100")
else:
print("Valid Score")
case "E15":
print("Example 15")
for i in range(3):
for j in range(4):
print("i:", i, "j:", j)
print()
case "E16":
print("Example 16")
for hours in range(24):
for minutes in range(60):
for seconds in range(60):
print(hours, ":", minutes, ":", seconds)
time.sleep(1)
case "E17":
print("Example 17")
n = 0
while n < 100:
print(n)
if n == 5:
break
n += 1
case "E18":
print("Example 18")
n = 0
while n < 10:
n += 1
if n % 3 == 0:
continue
print(n)
case "E19":
print("Example 19")
for x in range(3):
if x == 5:
print("breaking out!")
break
else:
print("Value of x: " + str(x))
case "Q":
print("Quit!")
done = True
case _:
print("Invalid Choice")
Assignment Source Code
print("Name: ") # add your name
print("Date: ") # add your date
print("Unit 3 Assignment")
# Problem 1
print("Problem 1")
# Problem 2
print("Problem 2")
# Problem 3
print("Problem 3")
# Problem 4
print("Problem 4")
# Problem 4
print("Problem 4")
# Problem 5
print("Problem 5")
# Problem 6
print("Problem 6")
# Problem 7
print("Problem 7")
# Problem 8
print("Problem 8")
# Problem 9
print("Problem 9")
# Problem 10
print("Problem 10")
# Problem 11
print("Problem 11")
# Problem 12
print("Problem 12")
# Problem 13
print("Problem 13")
# Problem 14
print("Problem 14")
# Problem 15
print("Problem 15")
# Problem 16
print("Problem 16")
# Problem 17
print("Problem 17")
# Problem 18
print("Problem 18")
# Problem 19
print("Problem 19")
# Problem 20
print("Problem 20")
Last updated