Program 1
Even or odd
Check if a number is even or odd.
python
n = int(input("Enter a number: "))
if n % 2 == 0:
print(n, "is even")
else:
print(n, "is odd")Topic 03 of 17
Make decisions with if / elif / else and master conditional logic.
Program 1
Check if a number is even or odd.
n = int(input("Enter a number: "))
if n % 2 == 0:
print(n, "is even")
else:
print(n, "is odd")Program 2
Find the largest using if/elif.
a, b, c = 10, 25, 17
if a >= b and a >= c:
print(a)
elif b >= c:
print(b)
else:
print(c)Program 1
Map scores to letter grades.
score = 82
grade = (
"A" if score >= 90 else
"B" if score >= 80 else
"C" if score >= 70 else
"D" if score >= 60 else "F"
)
print("Grade:", grade)Program 1
Python 3.10+ structural pattern matching.
def describe(point):
match point:
case (0, 0):
return "Origin"
case (x, 0):
return f"On x-axis at {x}"
case (0, y):
return f"On y-axis at {y}"
case (x, y):
return f"Point ({x}, {y})"
print(describe((0, 0)))
print(describe((3, 0)))
print(describe((2, 5)))