Skip to content

Commit ee71be2

Browse files
committed
Initial commit
1 parent 54a22d1 commit ee71be2

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

11.Bank Account/bank.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#11. Bank Account Management:Implement a program that allows users to create bank accounts, deposit and withdraw money, and check balances.
2+
3+
4+
def Bank():
5+
print("Welcome to Our Bank Services!")
6+
data = [
7+
{'name':'aryan','age':21,'amt':23500},
8+
{'name':'mohit','age':25,'amt':14200}
9+
]
10+
11+
12+
13+
while True:
14+
print("\n1.Create a new bank account")
15+
print("2.Deposit money")
16+
print("3.Withdraw money")
17+
print("4.Check Balance")
18+
print("5.Exit\n")
19+
20+
try:
21+
user_choice = int(input("Enter your choice="))
22+
except ValueError:
23+
print("Please enter number only from the given services.")
24+
25+
26+
27+
if user_choice == 1:
28+
x = input("Enter your name:").lower()
29+
for person in data:
30+
if x == person['name']:
31+
print('Your data has been found in our database!')
32+
break
33+
34+
else:
35+
age=input("Enter your age=")
36+
amt=input("Enter the cash amount=")
37+
data.append({'name':x,'age':age,'amt':amt})
38+
print("Success! Your new account has been created.")
39+
break
40+
41+
elif user_choice == 2:
42+
x = input("Enter the name of your account:").lower()
43+
try:
44+
y = int(input("Enter the amount you want to insert?"))
45+
if y<=0:
46+
print('Amount must be greater than 0.')
47+
continue
48+
except ValueError:
49+
print("Please enter a valid amount.")
50+
continue
51+
52+
account_found = False
53+
54+
for person in data:
55+
if x == person['name'] :
56+
person['amt'] = int(person['amt'])
57+
person['amt'] += y
58+
print(f"\nAmount:{y} has been deposited to account {x}")
59+
print(f"Balance:{person['amt']}\n")
60+
account_found = True
61+
break
62+
63+
if not account_found:
64+
print('please create your account first!')
65+
break
66+
67+
elif user_choice == 3:
68+
x = input("Enter the name of your account:").lower().strip()
69+
try:
70+
y = int(input("Enter the amount you want to withdraw?"))
71+
if y<=0:
72+
print('Amount must be a position number')
73+
continue
74+
except ValueError:
75+
print('Invalid input! Please enter a valid number for the amount.')
76+
continue
77+
78+
withdrawal_successful = False
79+
80+
for person in data:
81+
if x == person['name']:
82+
person['amt'] = int(person['amt'])
83+
84+
if y>person['amt']:
85+
print('Failure,Not sufficient funds in your bank account.')
86+
else:
87+
person['amt']-=y
88+
print(f"The amount withdrawn is {y}.")
89+
print(f"The remaining balance is={person['amt']}")
90+
withdrawal_successful = True
91+
break
92+
if not withdrawal_successful:
93+
print('Account not found or withdrawal failed.')
94+
95+
96+
elif user_choice == 4:
97+
print("\n")
98+
for x in data:
99+
print(f'{x}')
100+
101+
elif user_choice == 5:
102+
print("Welcome 🙏🏻")
103+
break
104+
105+
Bank()

0 commit comments

Comments
 (0)