-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
81 lines (72 loc) · 2.55 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
class Bank:
def __init__(self, name):
self.name = name
self.accounts = []
def add_account(self, account):
self.accounts.append(account)
class Account:
def __init__(self, number, owner, balance):
self.number = number
self.owner = owner
self.balance = balance
self.transactions = []
def deposit(self, amount):
self.balance += amount
self.transactions.append(Transaction(amount, 'Deposit'))
def withdraw(self, amount):
if self.balance >= amount:
self.balance -= amount
self.transactions.append(Transaction(amount, 'Withdrawal'))
else:
print('Insufficient funds')
class Transaction:
def __init__(self, amount, type):
self.amount = amount
self.type = type
def main():
bank_name = input('Enter bank name: ')
bank = Bank(bank_name)
print('Bank', bank_name, 'created successfully')
while True:
print('1. Create Account')
print('2. Deposit')
print('3. Withdraw')
print('4. Exit')
choice = int(input('Enter your choice: '))
if choice == 1:
acc_number = input('Enter account number: ')
acc_owner = input('Enter account owner name: ')
acc_balance = float(input('Enter opening balance: '))
account = Account(acc_number, acc_owner, acc_balance)
bank.add_account(account)
print('Account created successfully')
elif choice == 2:
acc_number = input('Enter account number: ')
amount = float(input('Enter amount to deposit: '))
account = find_account(bank.accounts, acc_number)
if account:
account.deposit(amount)
print('Deposit successful')
else:
print('Account not found')
elif choice == 3:
acc_number = input('Enter account number: ')
amount = float(input('Enter amount to withdraw: '))
account = find_account(bank.accounts, acc_number)
if account:
account.withdraw(amount)
print('Withdrawal successful')
else:
print('Account not found')
elif choice == 4:
print('Thank you for using the Bank Management System')
break
else:
print('Invalid choice')
def find_account(accounts, number):
for account in accounts:
if account.number == number:
return account
return None
if __name__ == '__main__':
main()