You are on page 1of 6

Practices for Lesson 2:

Advanced Features in Python

Copyright © 2020, Proton Expert Systems & Solutions. All rights reserved
1 Practices for Lesson 2: Advanced Features in Python
Practices for Lesson 2
Overview
In these practices for this lesson, you will learn to develop and run Python applications for building
a banking application using OOPS concept, multithreading, file handling, connecting to SQLite
database, create student table and query the table based on the conditions.

Copyright © 2020, Proton Expert Systems & Solutions. All rights reserved
2 Practices for Lesson 2: Advanced Features in Python
Practice of 2-1: Creating a Python Application using OOP concept
Overview
In this practice, you will learn to create a banking application using Object-oriented concept in
Python.

Assumptions: You should have completed the Practices for 1-3


Tasks:

1. Double click on Python IDLE shortcut on your local Desktop to start the Python Shell.
2. Click File from the drop down in Python IDLE, select New File.
3. Save the file by clicking File in the Menu and select Save option from the drop down.
4. Save the file as bank_application.py on your local file system.
5. Copy and paste the below code in bank_application.py file. The code consists of
functions to deposit, withdraw amount from the account and to check the available balance
in the account as shown below

import sys
#Create a bank account to perform deposit and withdrawal function
class Bank_Account:
def __init__(self):
#initialize balance to 0
self.balance=0
print("Welcome to the Banking System")

def deposit(self):
amt=float(input("Deposit Amount: "))
self.balance += amt
print("Amount Deposited: ",amt)
print("\n")

def withdraw(self):
amt = float(input("Amount to be withdrawn: "))
if self.balance>=amt:
self.balance-=amt
print("You Withdrew:", amt)
else:
print("\n Insufficient balance ")
print("\n")

def display(self):
print("Available Balance= ",self.balance)
print("\n")

Copyright © 2020, Proton Expert Systems & Solutions. All rights reserved
3 Practices for Lesson 2: Advanced Features in Python
# create an object
B = Bank_Account()

while 1:
print("Select your option from the below choice")
print("1. Deposit Amount")
print("2. Withdraw Amount")
print("3. Net Available Balance")
print("4. Continue Transaction")
print("5. Exit")
choice=int(input("Enter your choice : "))
print("\n")
if choice==1:
# Call functions using class object B
B.deposit()
elif choice==2:
B.withdraw()
elif choice==3:
B.display()
elif choice==4:
pass
elif choice==5:
print("Thank you, Visit again")
sys.exit()
else:
print("Invalid choice")
sys.exit()

Copyright © 2020, Proton Expert Systems & Solutions. All rights reserved
4 Practices for Lesson 2: Advanced Features in Python
6. Save bank_application.py file and click Run in the Menu and select Run Module option
from the drop down to run the program
7. On successful execution, provide the input and verify the output as shown below.

Copyright © 2020, Proton Expert Systems & Solutions. All rights reserved
5 Practices for Lesson 2: Advanced Features in Python
8. Close the file and close Python Shell, by clicking on ‘X’ icon in the Python Shell window.

Copyright © 2020, Proton Expert Systems & Solutions. All rights reserved
6 Practices for Lesson 2: Advanced Features in Python

You might also like