import random
class Bank:
def __init__(self):
self.dic={}
self.acctno=random.randrange(10000,100000,1)
def newAccount(self):
print("Enter your name")
self.name=input()
self.dic[self.name]={}
print("Enter the initial deposite ")
self.initAmount=int(input())
self.dic[self.name][self.acctno]=self.initAmount
def display(self):
print("Account creation has been successful. Your account number is ",self.acctno)
print()
print()
def existing(self,nam,actno):
self.nam=nam
self.actno=actno
if self.dic[self.nam][self.actno] >=0:
print("Authentication Successfull")
print()
return True
else:
print("Authentication Failed")
print()
return False
def withdrawal(self,nam,actno):
print("Enter a withdrawal amount ")
self.wit=int(input())
self.nam=nam
self.actno=actno
if self.dic[self.nam][self.actno]>=self.wit:
self.dic[self.nam][self.actno]=self.dic[self.nam][self.actno]-self.wit
print("Withdrawal was successful.")
print("Available balance : ",self.dic[self.nam][self.actno])
print()
else:
print("Insufficient balance ")
print()
def addamount(self,nam,actno):
self.nam=nam
self.actno=actno
print("Enter the amount you want to deposite ")
self.add=int(input())
print()
self.dic[self.nam][self.actno]=self.dic[self.nam][self.actno]+self.add
print("Deposite was successful.")
print("Available balance ",self.dic[self.nam][self.actno])
def displaybalance(self,nam,actno):
self.nam=nam
self.actno=actno
print("Available balance ",self.dic[self.nam][self.actno])
bank=Bank()
while True:
print("Enter 1 to create a new account ")
print("Enter 2 to access Existing account ")
print("Enter 3 to exit ")
userchoice=int(input())
if userchoice==1:
newaccount=bank.newAccount()
bank.display()
elif userchoice==2:
print("Enter your name ")
nam=input()
print("Enter your account number")
actno=int(input())
boolean=bank.existing(nam,actno)
if boolean:
while True:
print("Enter 1 to withdraw ")
print("Enter 2 to deposite ")
print("Enter 3 to display available balance ")
print("Enter 4 to go back to the previous menu ")
userinput=int(input())
if userinput==1:
bank.withdrawal(nam,actno)
elif userinput==2:
bank.addamount(nam,actno)
elif userinput==3:
bank.displaybalance(nam,actno)
elif userinput==4:
break
else:
continue
elif userchoice==3:
exit()