Sam.Natale Sam.Natale - 26 days ago 7x
Python Question

Bank ATM Program login

I want to make this program that acts as a bank, how do I make sure the correct ID number must be entered with the correct pin and have it depending on the id you entered print hello then their name and prompt how much money they have in the bank.

attempts = 0
store_id = [1057, 2736, 4659, 5691, 1234, 4321]
store_name = ["Jeremy Clarkson", "Suzanne Perry", "Vicki Butler-Henderson", "Jason Plato"]
store_balance = [172.16, 15.62, 23.91, 62.17, 131.90, 231.58]
store_pin = [1057, 2736, 4659, 5691]

start = int(input("Are you a member of the Northern Frock Bank?\n1. Yes\n2. No\n"))
if start == 1:
idguess = ""
pinguess = ""
while (idguess not in store_id) or (pinguess not in store_pin):
idguess = int(input("ID Number: "))
pinguess = int(input("PIN Number: "))
if (idguess not in store_id) or (pinguess not in store_pin):
print("Invalid Login")
attempts = attempts + 1
if attempts == 3:
print("This ATM has been blocked for too many failed attempts.")

elif start == 2:
name = str(input("What is your full name?: "))
pin = str(input("Please choose a 4 digit pin number for your bank account: "))
digits = len(pin)
balance = 100

while digits != 4:
print("That Pin is Invalid")
pin = str(input("Please choose a 4 digit pin number for your bank account: "))
digits = len(pin)



I'm very impressed by how much you've elaborated on your program. Here's how I would view your solution.

So to create a login simulation, I would instead use a dictionary. That way you can assign an ID to a PIN. For example:

credentials = {
    "403703": "121",
    "3900": "333",
    "39022": "900"

Where your ID is on the left side of the colon and the PIN is on the right. You would also have to assign the ID to a name that belongs to that ID using, you guessed it, a dictionary!

bankIDs = {
    "403703": "Anna",
    "3900": "Jacob",
    "39022": "Kendrick"

Now that you've done that, you can create your virtual login system using if/else control flow. I've made my code like this:

attempts = 0
    while attempts < 3:
        id_num = raw_input("Enter your ID: ")
        PIN = raw_input("Password: ")
        if (id_num in credentials) and (PIN == credentials[id_num]):
            print "login success."
            print "Login fail. try again."
            attempts += 1
    if attempts == 3:
        print "You have reached the maximum amount of tries."
except KeyboardInterrupt:
    print "Now closing. Goodbye!"

Note the try and except block is really optional. You could use the break operator like you did in your code if you wanted to, instead. I just like to put a little customization in there (Remember to break out of your program is CTRL-C). Finally, Python has a way of making life easier for people by using functions. Notice I used one where I put login(id_num). Above this while loop you'll want to define your login so that you can display a greeting message for that particular person. Here's what I did:

def login(loginid):
    print "Hello, %s!" % bankIDs[loginid]

Simple use of string formatting. And there you have it. The same can be done with displaying that person's balance. Just make the dictionary for it, then print the code in your login definition. The rest of the code is good as it is. Just make sure you've indented properly your while-loop inside the elif on the bottom of your code, and your last 2 lines as well. Hope I helped. Cheers!