Last time, we covered Booleans (True/False), comparison operators (==, !=, >, <, >=, <=), and if / elif / else to make decisions. You can now build programs that ‘decide’, like grading, temperature classification, and tiered ticket pricing. Today we go further: when a task must be repeated many times (e.g., summing 1 to 100, printing patterns, or generating a multiplication table), we won’t write hundreds of lines—we’ll use loops to let the computer repeat automatically.
Now students try to finish the following practice to review what we learned last unit:
n. Print Positive, Negative, or Zero.Answer example:
n = int(input("n = "))
if n > 0:
print("Positive")
elif n < 0:
print("Negative")
else:
print("Zero")
Imagine printing numbers from 1 to 10. Conditions can decide things, but you’d still write many lines to print them. A loop does that repetition for you. We’ll learn two common loops: while (repeat while a condition is true) and for (repeat over a count or sequence). Later, we’ll use nested loops to build the multiplication table.