0
0
Pythonprogramming~10 mins

While loop execution flow 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 run the loop while count is less than 5.

Python
count = 0
while count [1] 5:
    print(count)
    count += 1
Drag options to blanks, or click blank then click option'
A<
B>
C==
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' causes the loop to never run.
Using '==' runs the loop only if count equals 5, which is not the goal.
2fill in blank
medium

Complete the code to stop the loop when num reaches 10.

Python
num = 0
while num [1] 10:
    print(num)
    num += 2
Drag options to blanks, or click blank then click option'
A>
B<=
C<
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' causes the loop to run when num is 10, which may not be intended.
Using '>' or '>=' causes the loop to never run.
3fill in blank
hard

Fix the error in the loop condition to avoid an infinite loop.

Python
i = 5
while i [1] 0:
    print(i)
    i -= 1
Drag options to blanks, or click blank then click option'
A<=
B<
C>=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' causes the loop to never run.
Using '>=' or '<=' may cause off-by-one errors.
4fill in blank
hard

Fill both blanks to create a loop that prints numbers from 1 to 5.

Python
num = 1
while num [1] 5:
    print(num)
    num [2] 1
Drag options to blanks, or click blank then click option'
A<=
B+=
C-=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' excludes 5 from the output.
Using '-=' decreases num, causing an infinite loop.
5fill in blank
hard

Fill all three blanks to create a loop that prints even numbers from 2 to 10.

Python
start = [1]
end = [2]
while start [3] end:
    print(start)
    start += 2
Drag options to blanks, or click blank then click option'
A2
B10
C<=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' excludes the last number 10.
Starting at 0 or 1 prints unwanted numbers.