diff --git a/bank.py b/bank.py new file mode 100644 index 0000000..e21bf1b --- /dev/null +++ b/bank.py @@ -0,0 +1,21 @@ +class Bank: + + clients = [] + + def __init__(self, name): + self.name = name + + def add_client(self, client): + self.clients.append(client) + + def authentication(self, name, account_number): + for i in range(len(self.clients)): + if name == self.clients[i].name and account_number == self.clients[i].account_number: + print("Authentication successful!") + return self.clients[i] + + print(''' + Authentication failed! + Reason: account not found. + ''') + \ No newline at end of file diff --git a/bank1.2.png b/bank1.2.png new file mode 100644 index 0000000..058faab Binary files /dev/null and b/bank1.2.png differ diff --git a/client.py b/client.py new file mode 100644 index 0000000..3020aa3 --- /dev/null +++ b/client.py @@ -0,0 +1,35 @@ +from random import randint + +class Client: + + available_nums = [] + + def __init__(self, name, total_amount): + self.name = name + self.total_amount = total_amount + self.account_number = self.generate_random() + self.available_nums.append(self.account_number) + + def generate_random(self): + num = randint(10000, 99999) + while num in self.available_nums: + num = randint(10000, 99999) + return num + + def withdraw(self, amount): + if self.total_amount >= amount: + self.total_amount -= amount + print(f"The sum of {amount} has been withdrawn from your account balance.") + self.balance() + else: + print("Not enough money!") + + def deposit(self, amount): + self.total_amount += amount + print(f"The sum of {amount} has been added to your account balance.") + self.balance() + + def balance(self): + print(f"Your current account balance is: {self.total_amount}") + return self.total_amount + diff --git a/main.py b/main.py new file mode 100644 index 0000000..33629f4 --- /dev/null +++ b/main.py @@ -0,0 +1,62 @@ +from bank import Bank +from client import Client + +bank = Bank("ING") + +print(f"Welcome to {bank.name}!") + +available = True + +while available: + print(''' +Choose an option: + + 1. Open new bank account + 2. Open existing bank account + 3. Exit + + ''') + user_input = int(input()) + if user_input == 1: + print("To create an account, please fill in the information below.") + name = input("Name:") + amount = int(input("Deposit amount:")) + client = Client(name, amount) + bank.add_client(client) + print(f"Account created successfully! Your account number is: {client.account_number}") + elif user_input == 2: + print("To access your account, please enter your credentials below.") + name = input("Name:") + account_no = int(input("Account Number:")) + curr_client = bank.authentication(name, account_no) + if curr_client: + authorized = True + while authorized: + print(f''' + Welcome {curr_client.name}! + + Choose an option: + + 1. Withdraw + 2. Deposit + 3. Balance + 4. Exit + ''') + curr_input = int(input("1, 2, 3, or 4:")) + if curr_input == 1: + w_amount = int(input("Withdraw amount:")) + curr_client.withdraw(w_amount) + elif curr_input == 2: + d_amount = int(input("Deposit amount:")) + curr_client.deposit(d_amount) + elif curr_input == 3: + curr_client.balance() + elif curr_input == 4: + authorized = False + else: + print("Invalid input, please enter 1, 2, 3, or 4!") + elif user_input == 3: + available = False + else: + print('Input should be 1, 2, or 3!') + \ No newline at end of file