Python Forum
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")
Reply
#2
For start check our tutorial on inheritance: https://python-forum.io/Thread-Classes-C...nheritance
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


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

Forum Jump:

User Panel Messages

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