Welcome to Chapter 4: Loops! 🔄
💡 Think of it like this: A loop is like a merry-go-round — it keeps going around and around until we tell it to stop. A while loop keeps running as long as a condition is True.
Key concepts:
while loops run as long as the condition is Truebreak — exits the loop immediatelycontinue — skips to the next iterationThis exercise simulates a PIN entry system — the loop keeps asking until the correct PIN is entered (or max attempts reached).
# A while loop keeps going until the condition is False
count = 0
while count < 3:
print(f'Count is: {count}')
count += 1 # Don't forget this! Without it, infinite loop!
# Output:
# Count is: 0
# Count is: 1
# Count is: 2
Run your code
Incorrect PIN.
Incorrect PIN.
Incorrect PIN.
PIN accepted!