Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Bank:
- def __init__(self):
- self.client_details_list = []
- self.loggedIn = False
- self.cash = 200
- self.Transfer_cash = False
- def register(self, name, num, password):
- cash = self.cash
- conditions = True
- if len(str(num)) > 10 or len(str(num))<10:
- print("Invalid Phone number, please enter a 10 digit number.")
- conditions = False
- if len(password) < 5 or len(password) > 18:
- print("Enter password greater than 5 and less than 18 characters")
- conditions = False
- if conditions == True:
- print("Account created successfully")
- self.client_details_list = [name, num, password, cash]
- with open(f"{name}.txt","w") as f:
- for details in self.client_details_list:
- f.write(str(details)+"\n")
- def login(self, name, num, password):
- with open(f"{name}.txt", "r") as f:
- details = f.read()
- self.client_details_list = details.split("\n")
- if str(num) == str(self.client_details_list[1]):
- if str(password) in str(self.client_details_list):
- self.loggedIn = True
- else:
- print("wrong password brothers")
- else:
- print("wrong phone number")
- if self.loggedIn == True:
- print(f"{name} logged in")
- self.cash = int(self.client_details_list[3])
- self.name = name
- # else:
- # print("Invalid Credentials")
- def add_cash(self, name, amount):
- if amount>0:
- self.cash += amount
- with open(f"{name}.txt", "r") as f:
- details = f.read()
- self.client_details_list = details.split("\n")
- with open(f"{name}.txt","w") as f:
- f.write(details.replace(str(self.client_details_list[3]),str(self.cash)))
- print("Amount added successfully")
- else:
- print("Enter correct value of amount")
- def transfer_cash(self, name, num, amount):
- with open(f"{name}.txt", "r") as f:
- details = f.read()
- self.client_details_list = details.split("\n")
- if str(num) in self.client_details_list:
- self.Transfer = True
- if self.Transfer==True:
- total_cash = int(self.client_details_list[3]) + amount
- left_cash = self.cash - amount
- with open(f"{name}.txt","w") as f:
- f.write(details.replace(str(self.client_details_list[3]),str(total_cash)))
- with open(f"{self.name}.txt", "r") as f:
- details_2 = f.read()
- self.client_details_list = details_2.split("\n")
- with open(f"{self.name}.txt","w") as f:
- f.write(details_2.replace(str(self.client_details_list[3]),str(left_cash)))
- print("Amount Transferred Successfully to",name,"-",num)
- print("Balance left =",left_cash)
- self.cash = left_cash
- def update_password(self, password):
- if len(password) < 5 or len(password) > 18:
- print("Enter password greater than 5 and less than 18 characters")
- else:
- with open(f"{self.name}.txt", "r") as f:
- details = f.read()
- self.client_details_list = details.split("\n")
- with open(f"{self.name}.txt","w") as f:
- f.write(details.replace(str(self.client_details_list[2]),str(password)))
- print("Password successfully changed")
- def update_number(self, num):
- if len(str(num)) > 10 or len(str(num))<10:
- print("Invalid Phone number, please enter a 10 digit number.")
- else:
- with open(f"{self.name}.txt", "r") as f:
- details = f.read()
- self.client_details_list = details.split("\n")
- with open(f"{self.name}.txt","w") as f:
- f.write(details.replace(str(self.client_details_list[1]),str(num)))
- print("Number successfully changed")
- if __name__ == "__main__":
- Bank_object = Bank()
- print("Welcome to my Bank")
- print("1. Login")
- print("2. Create a New Account")
- choice = int(input("\nSelect a choice : "))
- if choice == 1:
- print("Logging in")
- name = input("Enter name : ")
- num = int(input("Enter Phone Number : "))
- password = input("Enter Password : ")
- Bank_object.login(name,num,password)
- while True:
- if Bank_object.loggedIn:
- print("1. Add amount")
- print("2. Check balance")
- print("3. Transfer amount")
- print("4. Edit profile")
- print("5. Logout")
- action = int(input("\nSelect an action : "))
- if action == 1:
- print("Balance = ",Bank_object.cash)
- amount = int(input("Enter amount to be credited : "))
- Bank_object.add_cash(name, amount)
- print("\n1. Back to menu")
- print("\n2. Logout")
- choice1 = int(input("\nEnter a choice : "))
- if choice1 == 1:
- continue
- elif choice1 == 2:
- Bank_object.loggedIn = False
- break
- elif action == 2:
- print("Balance = ",Bank_object.cash)
- print("\n1. Back to menu")
- print("\n2. Logout")
- choice1 = int(input("Enter a choice : "))
- if choice1 == 1:
- continue
- elif choice1 == 2:
- Bank_object.loggedIn = False
- break
- elif action == 3:
- print("Balance = ", Bank_object.cash)
- amount = int(input("Enter amount to be transferred : "))
- if amount <= Bank_object.cash:
- name = input("Enter name of recipient : ")
- num = int(input("Enter the phone number of the recipient : "))
- Bank_object.transfer_cash(name, num, amount)
- print("\n1. Back to menu")
- print("\n2. Logout")
- choice1 = int(input("Enter a choice : "))
- if choice1 == 1:
- continue
- elif choice1 == 2:
- Bank_object.loggedIn = False
- break
- elif amount < 0:
- print("Enter valid amount")
- elif amount > Bank_object.cash:
- print("Insufficient Funds")
- elif action == 4:
- print("1. Update Password")
- print("2. Updated Phone Number")
- update_choice = int(input("Select a choice"))
- if update_choice == 1:
- new_pass = input("Enter new password : ")
- Bank_object.update_password(new_pass)
- print("\n1. Back to menu")
- print("\n2. Logout")
- choice1 = int(input("Enter a choice : "))
- if choice1 == 1:
- continue
- elif choice1 == 2:
- Bank_object.loggedIn = False
- break
- elif update_choice == 2:
- new_num = int(input("Enter the new Number : "))
- Bank_object.update_number(new_num)
- print("\n1. Back to menu")
- print("\n2. Logout")
- choice1 = int(input("Enter a choice : "))
- if choice1 == 1:
- continue
- elif choice1 == 2:
- Bank_object.loggedIn = False
- break
- elif action == 5:
- break
- if choice == 2:
- print("Creating a new Account")
- name = input("Enter name : ")
- num = int(input("Enter Phone Number : "))
- password = input("Enter Password : ")
- Bank_object.register(name, num, password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement