-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
110 lines (96 loc) · 4.4 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# User parent class
class User():
def __init__(self, name: str, age: int):
#assert isinstance(age,int), f"Please enter a whole number for age"
self.name = name
self.age = age
def show_user_details(self):
return f"User Details:\n Name: {self.name.title()}\n Age: {self.age}"
# Account child class
class Account(User):
total_deposits = 0
total_withdrawals = 0
def __init__(self, name: str, age: int, balance):
super().__init__(
name, age
)
self.balance = balance
def deposit(self):
deposit_amount = float(input(f"{self.name.title()} Please enter how much you would like to deposit: "))
self.balance += deposit_amount
self.total_deposits += 1
print(f"Deposit Amount: $ {round(deposit_amount,2)}")
return f"Current Balance: $ {round(self.balance,2)}"
def withdraw(self):
withdrawal_amount = float(input(f"{self.name.title()}, please enter the amount you would like to withdraw: "))
if withdrawal_amount > self.balance:
return f"Insufficient Funds | Available Balance: $ {round(self.balance,2)}"
else:
self.balance -= withdrawal_amount
self.total_withdrawals += 1
print(f"Withdraw: $ {round(withdrawal_amount,2)}")
return f"Current Balance: $ {round(self.balance,2)}"
def view_balance(self):
return f"Current Balance: $ {self.balance}"
def menu_option(user_two):
print("Here is a list of options: ")
while True:
menu_option = int(input(" 1) Check Balance\n 2) Withdraw\n 3) Deposit\n 4) See Total Withdrawals\n 5) See Total Deposits\n 6) Quit\n"))
if menu_option == 1:
print(user_one_bank.view_balance())
if menu_option == 1 and user_two != None:
print(user_two_bank.view_balance())
elif menu_option == 2:
print(user_one_bank.withdraw())
if menu_option == 2 and user_two != None:
wd = input(f"{user_two.name} Would you like to withdraw?: Yes or No ")
if wd.lower() == 'yes':
print(user_two_bank.withdraw())
elif menu_option == 3:
print(user_one_bank.deposit())
if menu_option == 3 and user_two != None:
dep = input(f"{user_two.name} Would you like to make a deposit? Yes or No ")
if dep.lower() == 'yes':
print(user_two_bank.deposit())
elif menu_option == 4:
print(f"There have been {user_one_bank.total_withdrawals} withdrawals")
if menu_option == 4 and user_two != None:
print(f"There have been {user_two_bank.total_withdrawals} withdrawals")
elif menu_option == 5:
print(f"There have been {user_one_bank.total_deposits} deposits")
if menu_option == 5 and user_two != None:
print(f"There have been {user_two_bank.total_deposits} deposits")
elif menu_option == 6:
print("Thank you for choosing Lambda Bank.")
return False
break
else:
print("Please choose a number from 1-6")
def bank_creation(name):
balance = float(input(f"{name.name.title()}, how much money do you have? "))
return balance
while True:
print("Welcome to Lambda Bank!")
name = input("Enter your name: ")
age = int(input("Enter your age: "))
user_one = User(name,age)
user_two = None
new_user = input("Would you like to register a new user? Type 'No' to create your bank account. ")
if new_user.lower() == 'yes':
name = input("Enter the second user's name: ")
age = int(input("Enter the second user's age: "))
user_two = User(name, age)
print("Please create your accounts.")
user_one_balance = bank_creation(user_one)
user_two_balance = bank_creation(user_two)
user_one_bank = Account(user_one.name, user_one.age, user_one_balance)
user_two_bank = Account(user_two.name, user_two.age, user_two_balance)
flag = menu_option(user_two)
if flag == False:
break
else:
user_one_balance = bank_creation(user_one)
user_one_bank = Account(user_one.name, user_one.age, user_one_balance)
flag = menu_option(user_two)
if flag == False:
break