diff --git a/bank.py b/bank.py new file mode 100644 index 0000000..22add88 --- /dev/null +++ b/bank.py @@ -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.") + + diff --git a/client.py b/client.py new file mode 100644 index 0000000..4f86885 --- /dev/null +++ b/client.py @@ -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) + diff --git a/main.py b/main.py new file mode 100644 index 0000000..7e81ef2 --- /dev/null +++ b/main.py @@ -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 + +