Exit Chapter 05 ยท ๐Ÿ”€ Flow of Control โ€” Quiz

Playing as a guest? to earn XP and track your progress.

Question 1 of 56 0 correct so far

๐Ÿ”€ Flow of Control Quiz

Q1.

The order in which statements of a program are executed is called:

Explanation

Flow of control decides which statement runs next.

Q2.

What are the three basic kinds of flow of control?

Explanation

Statements run one after another (sequence), choose a path (selection) or repeat (iteration).

Q3.

Statements running one after another from top to bottom is called:

Explanation

Sequence is the default flow โ€” line by line.

Q4.

Choosing which block to run based on a condition is called:

Explanation

if statements are used for selection (decision making).

Q5.

Repeating a set of statements is called:

Explanation

Loops (for and while) are used for iteration.

Q6.

A line that starts a block (such as an if or a for) must end with:

Explanation

if, elif, else, for and while lines end with a colon.

Q7.

Which statement does nothing and is used as a placeholder for an empty block?

Explanation

pass is the empty statement in Python.

Q8.

What is the output of:

x = 5
if x > 10:
    print("Big", end=" ")
print("Done")
Explanation

x > 10 is False, so the if block is skipped; Done is outside the if and always prints.

Q9.

What is the output of:

x = 4
if x % 2 == 0:
    print("Even")
else:
    print("Odd")
Explanation

4 % 2 is 0, so the if block runs.

Q10.

In an ifโ€“elifโ€“else ladder, how many blocks run?

Explanation

Python checks conditions top to bottom and runs only the first True block.

Q11.

What is the output of:

m = 75
if m >= 90:
    print("A")
elif m >= 60:
    print("B")
elif m >= 40:
    print("C")
else:
    print("D")
Explanation

75 >= 90 is False, 75 >= 60 is True, so B prints and the rest are skipped.

Q12.

Which keyword is short for 'else if' in Python?

Explanation

Python uses elif.

Q13.

Can an if statement be written without an else part?

Explanation

A simple if has no else.

Q14.

An if statement written inside another if statement is called a:

Explanation

A nested if is used when one decision depends on another.

Q15.

What is the output of:

a = 5
if a > 0:
    if a > 10:
        print("X")
    else:
        print("Y")
Explanation

a > 0 is True; inside it, a > 10 is False, so the inner else prints Y.

Q16.

What error is given by:

if 5 > 2
    print("Yes")
Explanation

The colon after the condition is missing.

Q17.

What is the output of:

print(list(range(5)))
Explanation

range(5) starts at 0 and stops before 5.

Q18.

What is the output of:

print(list(range(2, 6)))
Explanation

range(start, stop) includes start and excludes stop.

Q19.

What is the output of:

print(list(range(1, 10, 3)))
Explanation

Start at 1 and jump by 3, stopping before 10.

Q20.

What is the output of:

print(list(range(10, 0, -2)))
Explanation

A negative step counts down; 0 is the stop value and is not included.

Q21.

What is the output of:

print(list(range(5, 1)))
Explanation

With the default step +1, you can't go from 5 up to 1, so the range is empty.

Q22.

In range(start, stop, step), which value is NEVER included?

Explanation

The sequence always stops before the stop value.

Q23.

What is the output of:

for i in range(3):
    print(i, end=" ")
Explanation

range(3) gives 0, 1, 2.

Q24.

What is the output of:

for ch in "CAT":
    print(ch, end="-")
Explanation

A for loop can go through each character of a string.

Q25.

How many times does this loop run?

for i in range(1, 11):
    print(i)
Explanation

It runs for i = 1 to 10.

Q26.

What is the output of:

s = 0
for i in range(1, 5):
    s = s + i
print(s)
Explanation

1 + 2 + 3 + 4 = 10.

Q27.

What is the output of:

f = 1
for i in range(1, 5):
    f = f * i
print(f)
Explanation

1 ร— 2 ร— 3 ร— 4 = 24.

Q28.

When finding a factorial, why do we start with fact = 1 and not fact = 0?

Explanation

Product accumulators start at 1; sum accumulators start at 0.

Q29.

Which loop is best when the number of repetitions is known in advance?

Explanation

A for loop with range() is used when you know how many times to repeat.

Q30.

Which loop repeats as long as a condition is True?

Explanation

A while loop keeps running while its condition is True.

Q31.

What is the output of:

i = 1
while i <= 3:
    print(i, end=" ")
    i += 1
Explanation

The loop runs while i is 1, 2 and 3.

Q32.

What happens in this code?

i = 1
while i <= 5:
    print(i)
Explanation

i is never updated, so i <= 5 is always True.

Q33.

The three steps needed for a correct while loop are:

Explanation

Give the variable a starting value, test it in while, and change it inside the loop.

Q34.

What is the output of:

n = 10
while n > 0:
    n = n - 3
print(n)
Explanation

n goes 10 โ†’ 7 โ†’ 4 โ†’ 1 โ†’ โˆ’2; then n > 0 is False.

Q35.

What is the output of:

n = 123
s = 0
while n > 0:
    s = s + n % 10
    n = n // 10
print(s)
Explanation

n % 10 takes the last digit and n // 10 removes it: 3 + 2 + 1 = 6.

Q36.

Which expression gives the LAST digit of a number n?

Explanation

The remainder after dividing by 10 is the last digit.

Q37.

Which statement immediately exits the loop?

Explanation

break stops the loop completely.

Q38.

Which statement skips the rest of the current round and goes to the next round?

Explanation

continue jumps to the next iteration.

Q39.

What is the output of:

for i in range(1, 6):
    if i == 3:
        break
    print(i, end=" ")
Explanation

When i becomes 3, the loop stops.

Q40.

What is the output of:

for i in range(1, 6):
    if i == 3:
        continue
    print(i, end=" ")
Explanation

continue skips only the round where i is 3.

Q41.

What is the output of:

for i in range(1, 10):
    if i % 4 == 0:
        break
print(i)
Explanation

The loop breaks when i is 4, and i keeps that value.

Q42.

A loop inside another loop is called a:

Explanation

In a nested loop, the inner loop runs completely for each round of the outer loop.

Q43.

How many times will "Hi" be printed?

for i in range(3):
    for j in range(4):
        print("Hi")
Explanation

Total runs = outer ร— inner = 3 ร— 4 = 12.

Q44.

What is the output of:

for i in range(1, 4):
    print("*" * i, end=" ")
Explanation

"*" * i repeats the star i times.

Q45.

What is the output of:

for i in range(1, 3):
    for j in range(1, 3):
        print(i * j, end=" ")
Explanation

i=1: 1, 2; i=2: 2, 4.

Q46.

Which code prints the multiplication table of 5 (5 to 50)?

Explanation

range(1, 11) gives 1 to 10, so 5 ร— 1 to 5 ร— 10 are printed.

Q47.

What is the output of:

x = 0
if x:
    print("Yes")
else:
    print("No")
Explanation

0 is treated as False in a condition.

Q48.

What is the output of:

for i in range(3):
    pass
print(i)
Explanation

pass does nothing; after the loop, i holds its last value, 2.

Q49.

What is the output of:

count = 0
for ch in "banana":
    if ch == "a":
        count += 1
print(count)
Explanation

"banana" has three a's.

Q50.

What is the output of:

for i in range(5, 0, -1):
    print(i, end="")
Explanation

The loop counts down from 5 to 1.

Q51.

What is the output of:

n = 9
is_prime = True
for i in range(2, n):
    if n % i == 0:
        is_prime = False
        break
print(is_prime, i)
Explanation

9 % 3 == 0, so is_prime becomes False and the loop breaks with i = 3.

Q52.

A for loop vs a while loop โ€” which statement is TRUE?

Explanation

Use for with a known count and while when you repeat until a condition changes.

Q53.

What error does this code give?

x = 8
if x > 5:
print(x)
Explanation

The statement inside the if block must be indented.

Q54.

What is the output of:

total = 0
for i in range(2, 11, 2):
    total += i
print(total)
Explanation

2 + 4 + 6 + 8 + 10 = 30.

Q55.

What is the output of:

i = 5
while i > 5:
    print(i)
print("End")
Explanation

The condition is False at the start, so the loop body never runs.

Q56.

Which value of age makes this print "Teen"?

if age >= 13 and age <= 19:
    print("Teen")
Explanation

Both conditions must be True; only 15 is between 13 and 19.