Advertisement
Kitood

Untitled

May 4th, 2023
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.65 KB | None | 0 0
  1. class Bank:
  2. def __init__(self):
  3. self.client_details_list = []
  4. self.loggedIn = False
  5. self.cash = 200
  6. self.Transfer_cash = False
  7.  
  8. def register(self, name, num, password):
  9. cash = self.cash
  10. conditions = True
  11. if len(str(num)) > 10 or len(str(num))<10:
  12. print("Invalid Phone number, please enter a 10 digit number.")
  13. conditions = False
  14.  
  15. if len(password) < 5 or len(password) > 18:
  16. print("Enter password greater than 5 and less than 18 characters")
  17. conditions = False
  18.  
  19. if conditions == True:
  20. print("Account created successfully")
  21. self.client_details_list = [name, num, password, cash]
  22. with open(f"{name}.txt","w") as f:
  23. for details in self.client_details_list:
  24. f.write(str(details)+"\n")
  25.  
  26. def login(self, name, num, password):
  27. with open(f"{name}.txt", "r") as f:
  28. details = f.read()
  29. self.client_details_list = details.split("\n")
  30. if str(num) == str(self.client_details_list[1]):
  31. if str(password) in str(self.client_details_list):
  32. self.loggedIn = True
  33. else:
  34. print("wrong password brothers")
  35. else:
  36. print("wrong phone number")
  37.  
  38. if self.loggedIn == True:
  39. print(f"{name} logged in")
  40. self.cash = int(self.client_details_list[3])
  41. self.name = name
  42.  
  43. # else:
  44. # print("Invalid Credentials")
  45.  
  46. def add_cash(self, name, amount):
  47. if amount>0:
  48. self.cash += amount
  49. with open(f"{name}.txt", "r") as f:
  50. details = f.read()
  51. self.client_details_list = details.split("\n")
  52.  
  53. with open(f"{name}.txt","w") as f:
  54. f.write(details.replace(str(self.client_details_list[3]),str(self.cash)))
  55.  
  56. print("Amount added successfully")
  57.  
  58. else:
  59. print("Enter correct value of amount")
  60.  
  61. def transfer_cash(self, name, num, amount):
  62. with open(f"{name}.txt", "r") as f:
  63. details = f.read()
  64. self.client_details_list = details.split("\n")
  65.  
  66. if str(num) in self.client_details_list:
  67. self.Transfer = True
  68.  
  69. if self.Transfer==True:
  70. total_cash = int(self.client_details_list[3]) + amount
  71. left_cash = self.cash - amount
  72. with open(f"{name}.txt","w") as f:
  73. f.write(details.replace(str(self.client_details_list[3]),str(total_cash)))
  74.  
  75. with open(f"{self.name}.txt", "r") as f:
  76. details_2 = f.read()
  77. self.client_details_list = details_2.split("\n")
  78.  
  79. with open(f"{self.name}.txt","w") as f:
  80. f.write(details_2.replace(str(self.client_details_list[3]),str(left_cash)))
  81. print("Amount Transferred Successfully to",name,"-",num)
  82. print("Balance left =",left_cash)
  83. self.cash = left_cash
  84.  
  85.  
  86. def update_password(self, password):
  87. if len(password) < 5 or len(password) > 18:
  88. print("Enter password greater than 5 and less than 18 characters")
  89.  
  90. else:
  91. with open(f"{self.name}.txt", "r") as f:
  92. details = f.read()
  93. self.client_details_list = details.split("\n")
  94.  
  95. with open(f"{self.name}.txt","w") as f:
  96. f.write(details.replace(str(self.client_details_list[2]),str(password)))
  97. print("Password successfully changed")
  98.  
  99. def update_number(self, num):
  100. if len(str(num)) > 10 or len(str(num))<10:
  101. print("Invalid Phone number, please enter a 10 digit number.")
  102. else:
  103. with open(f"{self.name}.txt", "r") as f:
  104. details = f.read()
  105. self.client_details_list = details.split("\n")
  106.  
  107. with open(f"{self.name}.txt","w") as f:
  108. f.write(details.replace(str(self.client_details_list[1]),str(num)))
  109. print("Number successfully changed")
  110.  
  111.  
  112.  
  113. if __name__ == "__main__":
  114. Bank_object = Bank()
  115. print("Welcome to my Bank")
  116. print("1. Login")
  117. print("2. Create a New Account")
  118. choice = int(input("\nSelect a choice : "))
  119.  
  120. if choice == 1:
  121. print("Logging in")
  122. name = input("Enter name : ")
  123. num = int(input("Enter Phone Number : "))
  124. password = input("Enter Password : ")
  125. Bank_object.login(name,num,password)
  126. while True:
  127. if Bank_object.loggedIn:
  128. print("1. Add amount")
  129. print("2. Check balance")
  130. print("3. Transfer amount")
  131. print("4. Edit profile")
  132. print("5. Logout")
  133. action = int(input("\nSelect an action : "))
  134. if action == 1:
  135. print("Balance = ",Bank_object.cash)
  136. amount = int(input("Enter amount to be credited : "))
  137. Bank_object.add_cash(name, amount)
  138. print("\n1. Back to menu")
  139. print("\n2. Logout")
  140. choice1 = int(input("\nEnter a choice : "))
  141. if choice1 == 1:
  142. continue
  143. elif choice1 == 2:
  144. Bank_object.loggedIn = False
  145. break
  146.  
  147. elif action == 2:
  148. print("Balance = ",Bank_object.cash)
  149. print("\n1. Back to menu")
  150. print("\n2. Logout")
  151. choice1 = int(input("Enter a choice : "))
  152. if choice1 == 1:
  153. continue
  154. elif choice1 == 2:
  155. Bank_object.loggedIn = False
  156. break
  157.  
  158. elif action == 3:
  159. print("Balance = ", Bank_object.cash)
  160. amount = int(input("Enter amount to be transferred : "))
  161. if amount <= Bank_object.cash:
  162. name = input("Enter name of recipient : ")
  163. num = int(input("Enter the phone number of the recipient : "))
  164. Bank_object.transfer_cash(name, num, amount)
  165. print("\n1. Back to menu")
  166. print("\n2. Logout")
  167. choice1 = int(input("Enter a choice : "))
  168. if choice1 == 1:
  169. continue
  170. elif choice1 == 2:
  171. Bank_object.loggedIn = False
  172. break
  173. elif amount < 0:
  174. print("Enter valid amount")
  175.  
  176. elif amount > Bank_object.cash:
  177. print("Insufficient Funds")
  178.  
  179. elif action == 4:
  180. print("1. Update Password")
  181. print("2. Updated Phone Number")
  182. update_choice = int(input("Select a choice"))
  183. if update_choice == 1:
  184. new_pass = input("Enter new password : ")
  185. Bank_object.update_password(new_pass)
  186. print("\n1. Back to menu")
  187. print("\n2. Logout")
  188. choice1 = int(input("Enter a choice : "))
  189. if choice1 == 1:
  190. continue
  191. elif choice1 == 2:
  192. Bank_object.loggedIn = False
  193. break
  194.  
  195. elif update_choice == 2:
  196. new_num = int(input("Enter the new Number : "))
  197. Bank_object.update_number(new_num)
  198. print("\n1. Back to menu")
  199. print("\n2. Logout")
  200. choice1 = int(input("Enter a choice : "))
  201. if choice1 == 1:
  202. continue
  203. elif choice1 == 2:
  204. Bank_object.loggedIn = False
  205. break
  206.  
  207. elif action == 5:
  208. break
  209.  
  210.  
  211. if choice == 2:
  212. print("Creating a new Account")
  213. name = input("Enter name : ")
  214. num = int(input("Enter Phone Number : "))
  215. password = input("Enter Password : ")
  216. Bank_object.register(name, num, password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement