Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Classes
#1
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")
Quote
#2
For start check our tutorial on inheritance: https://python-forum.io/Thread-Classes-C...nheritance
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Using classes? Can I just use classes to structure code? muteboy 5 1,768 Nov-01-2017, 04:20 PM
Last Post: metulburr

Forum Jump:


Users browsing this thread: 1 Guest(s)