Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions bank.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from client import Client

class Bank(Client):
clients=[] # clients will be stored as its unique path in memory, not as name

def __init__(self, name):
self.name=name



@classmethod
def add_client(cls,client):
cls.client=client
cls.clients.append(client)


def authentication(self,name,acc_No): #account number key to verify its name from database dict in CLient class
try :
if Client.data_base[acc_No]["name"] == name :
return True
except KeyError :
print("Authentication failed! \nReason: Account not found.")


32 changes: 32 additions & 0 deletions client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import random

class Client():
data_base={} #We keep clients as 'no : name,amount'
def __init__(self,name,total_amount):
self.name=name
self.total_amount=total_amount
self.acc_No=(''.join(random.sample('0123456789', 5)))#we assign 5 digits number as str
print("Account created successfully! Your account number is: %s "%(self.acc_No))
Client.data_base[self.acc_No]={"name" : self.name ,"total_amount" : self.total_amount}
def updated_amount(self): #We need to save in dictionary current amount after transactions
Client.data_base.update({self.acc_No : {"total_amount" : self.total_amount}})
print("Transaction done.Now,you have : %s"% (self.total_amount))


def withdraw(self,amount):
self.total_amount -= amount
if amount>self.total_amount:
raise "insufficient balance"
else:
self.updated_amount()

def deposit(self,amount):
self.total_amount+=amount
print("%s has been added your account."%(amount))
self.updated_amount()


def balance(self):
s='Name :%s , Account Number : %s ,Current Balance : %d '%(self.name,self.acc_No,self.total_amount)
print(s)

54 changes: 54 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from client import Client
from bank import Bank



int_bank=Bank("International")
while True:
option =input("""Welcome to International Bank
Choose an option:
1. Open new bank account
2. Open existing bank account
3. Exit \n Enter :""")
if option == "1":
name=input("Name :")
total_amount=int(input("Amount :"))
client=Client(name,total_amount)
int_bank.add_client(client)
print ("Acoount of %s,%s has been added"%(name,total_amount))

elif option=="2":
print("To access your account, please enter your credentials below.")
acc_No=input("Account No : ")
name=input("Name : ")
if int_bank.authentication(name,acc_No):

while True:
choice=input( """
Welcome %s !
Choose an option:
1. Withdraw
2. Deposit
3. Balance
4. Exit
"""%(name))
if choice=="1":
amount=int(input("Withdraw Amount : "))
for i in Bank.clients:
i.withdraw(amount)
elif choice=="2":
amount=int(input("Deposit Amount : "))
for i in Bank.clients:
i.deposit(amount)

elif choice=="3":
for i in Bank.clients:
i.balance()
elif choice=="4":
break

elif (option=="3"):
print("See you soon...")
break