If…else practice and the elif operator
Answers are for parents and teachers.
1
What does an if…else program for even or odd print for 25 (juft/toq)?
toq
2
Write a program that finds the smaller of two numbers (4 for 9 and 4).
a = int(input()) ⏎ b = int(input()) ⏎ if a < b: ⏎ m = a ⏎ else: ⏎ m = b ⏎ print(m)
3
Write a program for a typed hour s (0–23) that prints “ertalab” if s < 12, “kun” if s < 18 and “kech” otherwise.
s = int(input()) ⏎ if s < 12: ⏎ print("ertalab") ⏎ elif s < 18: ⏎ print("kun") ⏎ else: ⏎ print("kech")
4
Why would the condition m <= 5 be wrong standing alone (as if m <= 5) in the season program?
It would take months 1 and 2 as spring too; in the elif chain the winter months have already been separated.