0
0
Pythonprogramming~10 mins

Break statement behavior in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to stop the loop when the number 3 is found.

Python
for num in range(5):
    if num == 3:
        [1]
    print(num)
Drag options to blanks, or click blank then click option'
Abreak
Breturn
Cpass
Dcontinue
Attempts:
3 left
💡 Hint
Common Mistakes
Using continue instead of break, which skips the rest of the loop but does not stop it.
Using pass, which does nothing and continues the loop.
2fill in blank
medium

Complete the code to exit the while loop when count reaches 5.

Python
count = 0
while True:
    print(count)
    count += 1
    if count == 5:
        [1]
Drag options to blanks, or click blank then click option'
Aexit
Bcontinue
Cbreak
Dstop
Attempts:
3 left
💡 Hint
Common Mistakes
Using continue, which skips to the next iteration but does not stop the loop.
Using exit or stop, which are not valid Python statements for loops.
3fill in blank
hard

Complete the code to stop the loop when the letter 'a' is found.

Python
letters = ['b', 'c', 'a', 'd']
for letter in letters:
    if letter == 'a':
        [1]
    print(letter)
Drag options to blanks, or click blank then click option'
Acontinue
Breturn
Cpass
Dbreak
Attempts:
3 left
💡 Hint
Common Mistakes
Using continue instead of break, which does not stop the loop.
4fill in blank
hard

Fill both blanks to create a loop that prints numbers until it reaches 4, then stops.

Python
for i in range(10):
    print(i)
    if i [1] 4:
        [2]
Drag options to blanks, or click blank then click option'
A==
B<
Cbreak
Dcontinue
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '==' in the condition.
Using continue instead of break, which skips but does not stop the loop.
5fill in blank
hard

Fill all three blanks to create a loop that prints only numbers less than 5 and stops when it reaches 7.

Python
for num in range(10):
    if num [1] 7:
        [2]
    if num [3] 5:
        print(num)
Drag options to blanks, or click blank then click option'
A>=
Bbreak
C<
Dcontinue
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators.
Using continue instead of break to stop the loop.