What is an algorithm?
A step-by-step procedure to solve a problem.
What is a loop?
A loop repeats a block of code.
What does break do?
It stops the loop completely.
What is a bug?
An error or unexpected problem in a program.Q: What is a nested loop?
What is a nested loop?
A loop inside another loop.
What are the three basic programming structures?
Sequence, Selection and Iteration.
Name three types of loops.
While loop, For loop and Nested loop.
What does continue do?
It skips the current iteration and moves to the next one.
What is debugging?
The process of finding and fixing bugs in a program.
Which loop is placed inside another loop?
Inner loop.
What is selection?
Making a choice based on a condition using if/else.
What is a while loop?
A loop that executes while a condition is true.
What is the difference between break and continue?
break stops the entire loop; continue skips the current iteration.
What is the purpose of debugging?
To find and fix errors/bugs in a program.
If the outer loop runs 2 times and the inner loop runs 3 times, how many times does the inner statement execute?
6 times.
What is iteration?
Repeating a task or set of instructions.
What does range(0,6) produce?
0,1,2,3,4,5
When would you use continue instead of break?
When you want to skip one iteration but continue the loop.
Find the bug:
for i in range(1,-5):
range(1,-5) is the bug
How many stars are printed?
for i in range(1,4):
for j in range(1,5):
print("*")
12 stars.
A program needs to: check whether it is raining, repeat taking attendance for 5 students, and then display “Attendance Complete”. Which three structures are being used, where and why?
Selection for checking rain, Iteration for repeating attendance 5 times, and Sequence because the instructions happen in order.
Without running the code, explain how many times Hello is printed:
for i in range(2,8):
print("Hello")
6 times — range(2,8) gives 2, 3, 4, 5, 6, 7.
What will happen when i becomes 3?
for i in range(1,7):
if i == 3:
continue
if i == 5:
break
print(i)
It prints 1, 2, 4. 3 is skipped and when i = 5, the loop stops.
Find and explain the bug:
i = 1
while i <= 5:
print(i)
i is never increased, so the condition always remains true. Add i = i + 1 inside the loop.
You want a sprite to draw a 3 × 3 square of dots using nested loops. The outer loop controls the rows, and the inner loop controls the dots in each row.
How many times should each loop repeat?