Prerequisite: Object Oriented Programming in Python
Let’s write a simple Python program using OOP concept to perform some simple bank operations like deposit and withdrawal of money.
First of all, define class
Bankacccount. This step is followed by defining a function using
__init__. It is run as soon as an object of a class is instantiated. This
__init__ method is useful to do any initialization you want to do with object, then we have the default argument
This step is followed by declaring that balance is 0 using
self argument then we simply print a statement welcoming to Machine. In function
withdraw , amount is taken as input(in float) and is then added/subtracted to the balance. Thus resultant balance is printed in next line.
Use an if condition to check whether there is a sufficient
amount of money available in the account to process a fund withdrawal.
Next, we use a
display function to display the remianing balnce in the account. Then we create a object and call it to get the program executed.
Below is the implementation:
Hello !!! Welcome to Deposit&Withdrawal Machine Enter amount to be deposited: Amount Deposited: 1000.0 Enter amount to be withdrawn: You Withdrew: 500.0 Net Available Balance = 500.0
- How to create an empty class in Python?
- How to create a list of object in Python class
- Program to create grade calculator in Python
- Python program to create a list centered on zero
- Python Program to create an OTP by squaring and concatenating the odd digits of a number
- How to create a Class in JShell of Java 9
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python program to find number of local variables in a function
- Python | Create a dictionary using list with none values
- Python | Ways to create triplets from given list
- Python | Create list of numbers with given range
- Create a tuple from string and list - Python
- Python | Create an empty text file with current date as its name
- Python | Create a Pandas Dataframe from a dict of equal length lists
- self in Python class
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : lennyatomz