Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

Simple bank operation program using python class and member functions?

Description

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

Process

   Create Bank class.

   Create deposit,withdraw and show_balance methods.

   Declare name and balance.

   Create object for Bank class.

   Calling the methods using objects.

Sample Code

#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()

Screenshots
Simple bank operation program using python class and member functions