Password Gate ๐
An if asks once. A while keeps asking until it gets what it
wants โ like a little sibling. ๐
guess = input("Password? ")
while guess != "dragon":
print("๐ซ Wrong! Try again.")
guess = input("Password? ")
print("๐ ACCESS GRANTED!")
!= means "is not equal to". So that loop says: while the guess is
not the password, keep going round.
โ ๏ธ Super important: you must ask again inside the loop. If you
forget, guess never changes, the loop never ends, and your program
spins forever. (Hit โน Stop if that happens โ it's happened to every
programmer alive.) ๐
Your mission
Build a password gate:
- Pick a secret password
- Keep asking with a
whileloop until they type it exactly right - Tease them for every wrong guess ๐
- Print a triumphant message when they finally get in
Your code
Press โถ Run to see what your code does!