oop - Python checking account simulator -


i have been working on oop program in python 3.0 simulates checking account , ran bug can't figure out. here is: in main part of program gave user multiple options such , exit, withdraw , deposit , , create new account. when user selects "create new account " program creates object , variable name has variable , im not sure how access atributes object labeled variable.basically asking is, how make variable name variable computer can keep track of , use access attributes of object? here program have far(if helps?):

class checking(object):     """a personal checking acount"""      def __init__(self , name, balance):         print("a new checking acount has been created")         self.name = name         self.balance = balance       def __str__(self):         rep = "balance object\n"         rep += "name of acount" + self.name + "\n"         rep += "balance " + self.balance + "\n"         return rep       def display(self):         print("\nyour acount name ",self.name)         print("your balance is",self.balance)       def deposit(self):         amount = int(input("\nplease enter amount of money wish diposit"))         self.balance += amount         print("\nthe balance of 'chris' ", self.balance)      def withdraw(self):         amount = int(input("\nplease enter amount wish withdraw "))         while amount > self.balance:             print("is invalid amount")             amount = int(input("\nplease enter amount wish withdraw "))         self.balance -= amount         print("\nthe balance of 'chris' ", self.balance)           answer = none      while answer != "0":         answer = input("""what action take?         0 exit         1 deposit         2 withdraw         3 add acount""")         if answer == "1":             input("ener pin").deposit()         if answer == "2":             input("enter pin ").withdraw()         if answer == "3":             input("enter num") = checking(name = input("\nwhat want acount name be?"), balance = 0)             input("enter pin").display()             print(checking)      input("\n\npress enter exit") 

use dictionary; store accounts in accounts dictionary acount number key:

accounts = {}  # ... if answer == 3:     account_number = input("enter num")     account_name = input("\nwhat want acount name be?")     accounts[account_number] = checking(name=account_name, balance=0) 

now can list accounts user has, example:

for account_number, account in accounts.items():     print('account number: {}, account name: {}'.format(account_number, account.name)) 

etc.

using local variables variable number of items same never idea. in case use lists or dictionaries instead.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -