Python Forum
Need help with pseuo -bank account using OOP
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with pseuo -bank account using OOP
#12
data = {'1': 'abcde', '2': '2357', '3': '11235'}
while True:
    pin = input('pin? ')
    if pin in data:
        text = data[pin]
        while True:
            index = int(input('index? '))
            if index < 0:
                break
            else:
                print(text[index])
    elif pin[0] in 'qQ':
        break
    else:
        print('Invalid pin.')
This is not something you would link to your code. This is an outline of what your code should look like, with a dummy example using strings instead of account objects.

The data dictionary has the pins for the keys, and the "accounts" (strings) for the values.

The outer loop is to get the pin from the user. Basic input of the pin. The if statement checks if the pin is a valid pin, and I will describe that section of the code in the next paragraph. The elif statement (I rewrote it to make it more clear) checks that the input from the user is in 'q' or 'Q', which would indicate quitting the application. If so, it breaks out of the outer loop. The else statement treats everything else as an invalid pin. The loop keeps asking for a pin until the user quits.

If there is a valid pin, the text variable (this would be your account object) gets the value from the data dictionary for the pin. The inner loop then asks for an index. This is where you would ask if they want to deposit, withdraw, get a balance, or whatever. The if statement checks for a negative index, which is the dummy quit command for the inner loop. You would have a quit option that would trigger here. You would then have a bunch of elif statements to handle the valid commands, and an else statement for invalid commands.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: Need help with pseuo -bank account using OOP - by ichabod801 - Jul-08-2017, 11:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Different results of code with local account and technical account dreyz64 7 3,741 Mar-05-2020, 11:50 AM
Last Post: dreyz64

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020