Dec-17-2019, 10:17 AM
Hey so ive been trying to do atm code and wanted to know how do i make classes inherit other classes attributes for example having 2 classes of base account and savings account and would make third class where all actions happens such as withdraw ect... point of this code is to select 1 of 2 bank accounts and output the results of specific accounts
class Account: def __init__(self, pin): self.pin = pin self.error = "Enter a valid pin code, Please try again" def login(self): if self.pin == log_pin: print(self.pin, "Successful Login!") else : print(self.error) quit() class Saving: def __init__(self, spin): self.spin = spin self.serror = "Enter a valid pin code, Please try again" def login(self): if self.pin == log_pin: print(self.pin, "Successful Login!") else : print(self.error) quit() acc = Account("1234") log_pin = input('please enter your pin code') acc.login() name=input("Name on your bank account? ") name2=input("Name on your savings bank account? ") balance=float(input("Your current balance? ")) def printMenu(): print(name,"Welcome to the Lots of Money Bank") print("Enter 'b'(balance), 'd'(deposit), 'w'(withdraw), or'q'(quit)") def getTransaction(): transaction=str(input("What would you like to do? ")) return transaction def withdraw(bal,amt): if(bal<0): bal=bal-10 else: bal=bal-amt return bal def formatCurrency(amt): return "$%.2f" %amt printMenu() command=str(getTransaction()) while command!="q": if (command=="b"): if name is true print(name,"Your current balance is",formatCurrency(balance)) printMenu() command=str(getTransaction()) elif (command=="d"): amount=float(input("Amount to deposit? ")) balance=balance+amount printMenu() command=str(getTransaction()) elif (command == "w"): amount = float(input("Amount to withdraw? ")) balance = withdraw(balance, amount) printMenu() command = str(getTransaction()) else: print("Incorrect command. Please try again.") printMenu() command=str(getTransaction()) print(name,"Goodbye! See you again soon")