Predict the Output
Beginner · Predict the output · from Python For Loops: Iterate Over Anything with Examples
From the lesson: Python For Loops: Iterate Over Anything with Examples
Imagine you're a teacher with 30 students. You need to print a report card for each one. Would you write 30 separate print statements? Of course not. You'd tell the computer: "for each student, print their report card." That's exactly what a for loop does.
Read the lessonWithout running the code, predict exactly what it will print. Pay close attention to the range() arguments and the if condition.
Then run it to check your answer.
for num in range(1, 8, 2):
if num > 4:
print(f"{num} is big")
else:
print(f"{num} is small")
More For Loops exercises
- Print the Shopping ListBeginner
- Sum Numbers 1 to 10Beginner
- Fix the Bug: Letter CounterBeginner
- Numbered MenuBeginner
- Reverse a StringBeginner
- Student Grade ReportBeginner
All Python exercises · 50 practice problems · Control Flow quiz