-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython Banking Program.py
More file actions
64 lines (54 loc) · 1.8 KB
/
Copy pathPython Banking Program.py
File metadata and controls
64 lines (54 loc) · 1.8 KB
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
# Python Banking Program
def show_balance(balance):
print()
print(f"Your balance is ${balance: .2f}")
print()
def deposit(balance):
try:
amount = float(input("Enter the amount that you want to deposit in your account: "))
if amount <= 0:
print("The amount needs to be above zero!")
else:
balance += amount
except ValueError:
print("Invalid input. Please enter a numeric value.")
return balance
def withdraw(balance):
try:
amount = float(input("Enter the amount that you want to withdraw from your account: "))
if amount > balance:
print('Your withdrawal must be less than or equal to your current balance.')
elif amount <= 0:
print("Withdrawal amount must be greater than zero!")
else:
balance -= amount
except ValueError:
print("Invalid input. Please enter a numeric value.")
return balance
def main():
balance = 0
while True:
print()
print("********************************")
print("* Banking Program *")
print("********************************")
print("1. Show balance")
print("2. Deposit")
print("3. Withdraw")
print("4. Exit")
print("********************************")
print()
try:
choice = int(input("Enter your choice (1-4): "))
except ValueError:
continue
if choice == 1:
show_balance(balance)
elif choice == 2:
balance = deposit(balance)
elif choice == 3:
balance = withdraw(balance)
elif choice == 4:
break
print("Thank you for using our services")
main()