Simple bank operation program using python class and member functions?

Description

To create a simple python program for bank operations in python3.

   Create Bank class.

   Create deposit,withdraw and show_balance methods.

   Declare name and balance.

   Create object for Bank class.

   Calling the methods using objects.

#bank class

class Bank:

def __init__(self, name, balance=500):

self.name = name

self.balance = balance

#deposit method

def deposit(self, amount):

self.balance += amount

#withdraw method

def withdraw(self, amount):

if amount > self.balance:

raise ValueError(“insufficient funds”)

self.balance -= amount

#show method

def show_balance(self):

#are accessor methods needed in Python?

return self.balance

#main method

def main():

customer1 = Bank(‘Sathish’)

print(“Initial balance”)

print(customer1.show_balance())

customer1.deposit(500)

print(“\n”)

print(“After deposit”)

print(customer1.show_balance())

print(“\n”)

print(“After withdrawal”)

customer1.withdraw(500)

print(customer1.show_balance())

if __name__ == “__main__”:

main()

Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit