16. Enter PIN (+10 XP)


# Loop


A loop is a programming tool that repeats some code or a set of instructions until a specified condition is reached. As a programmer, you’ll find that you rely on loops all the time!

You’ll hear the generic term “iterate” when referring to loops; iterate simply means “to repeat”.

The first kind of loop that we are going to learn is the while loop. You can think of the while loop like the traffic circle.


# Instructions


Before we dive deep into while loop, let's do a demo!

Create a enter_pin.py program and type in the following:

          
          print("BANK OF CODéDEX")  

          pin = input("Enter your PIN: ")
          
          while pin != '1234':
            pin = input("Incorrect PIN. Enter your PIN again: ")
          
          if pin == '1234':
            print("PIN accepted!")
          
        

Run the program.

When the program asks you to Enter your PIN:, try the following:

Press 1111 and press enter.

Press 2019 and press enter.

Press 1234 and press enter.


Back

Solution: enter_pin.py