0
0
Pythonprogramming~10 mins

while True pattern 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 create an infinite loop using while.

Python
while [1]:
    print("Looping forever")
Drag options to blanks, or click blank then click option'
A0
BFalse
CNone
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using False or 0 as the condition, which stops the loop immediately.
Using None, which is not a boolean and causes an error.
2fill in blank
medium

Complete the code to break out of the infinite loop when user types 'exit'.

Python
while True:
    user_input = input("Type something: ")
    if user_input == [1]:
        break
Drag options to blanks, or click blank then click option'
A"quit"
B"exit"
C"stop"
D"end"
Attempts:
3 left
💡 Hint
Common Mistakes
Using words other than 'exit' which do not stop the loop.
Forgetting to put quotes around the string.
3fill in blank
hard

Fix the error in the loop condition to make it an infinite loop.

Python
while [1] == True:
    print("Running")
Drag options to blanks, or click blank then click option'
ATrue
B1
CFalse
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using False or 0 which stops the loop.
Using 1 which works but is less clear than True.
4fill in blank
hard

Fill both blanks to create a loop that asks for a number and stops when the number is 0.

Python
while [1]:
    num = int(input("Enter number: "))
    if num [2] 0:
        break
Drag options to blanks, or click blank then click option'
ATrue
BFalse
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using while False which never runs the loop.
Using != which breaks on wrong condition.
5fill in blank
hard

Fill all three blanks to create a loop that asks for a password and stops when the correct password is entered.

Python
while [1]:
    pwd = input("Enter password: ")
    if pwd [2] [3]:
        break
Drag options to blanks, or click blank then click option'
ATrue
B==
C"secret123"
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using != which breaks on wrong password.
Forgetting quotes around the password string.