Repeating Yourself using a While Loop

No intro yet, sorry.

enterpin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from __future__ import print_function
input = raw_input

def main():
    pin = 12345
    print("WELCOME TO THE BANK OF PYTHON.")
    entry = int(input("ENTER YOUR PIN: "))

    while entry != pin:
        print("\nINCORRECT PIN. TRY AGAIN.")
        entry = int(input("ENTER YOUR PIN: "))

    print("\nPIN ACCEPTED. YOUR ACCOUNT BALANCE IS $425.17")

if __name__ == "__main__":
    main()

What You Should See

WELCOME TO THE BANK OF PYTHON.
ENTER YOUR PIN: 123

INCORRECT PIN. TRY AGAIN.
ENTER YOUR PIN: 1234

INCORRECT PIN. TRY AGAIN.
ENTER YOUR PIN: 12345

PIN ACCEPTED. YOUR ACCOUNT BALANCE IS $425.17

No explanation yet, sorry. Hopefully the code is enough. If you're already this far into the assignments, the code is probably enough.

Study Drills

  1. Ask for a password (string) before asking them for a PIN. Add another while loop so that they don't even get to type in a PIN until they get the password right.



©2017 Graham Mitchell