| KC | Knowledge Check |
Loops in Python
The Knowledge Check is intended to support learning and self-assessment. The questions highlight the key concepts of this unit and help prepare for the final examination.
The Knowledge Check is not graded.
1️⃣ Theory
What is the purpose of a loop in Python?
Briefly explain the difference between a for loop and a while loop.
2️⃣ For Loop
Write a Python for loop that prints the numbers from 1 to 5.
Expected output:
1
2
3
4
5
3️⃣ Loop and List
Assume:
numbers = [3, 6, 9]
Write a for loop that prints each value in the list.
4️⃣ While Loop
Write a while loop that prints the numbers from 1 to 3.
Expected output:
1
2
3
5️⃣ Loop with Condition
Write a Python program that prints all numbers from 1 to 10 that are greater than 5.
Use a loop and an if statement.
Discussion
The solutions will be discussed during the course session.