-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbankingprob.py
More file actions
44 lines (38 loc) · 1.07 KB
/
bankingprob.py
File metadata and controls
44 lines (38 loc) · 1.07 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
# Python Banking Problem
def show_balance(balance):
print(f"Your balance is: ${balance:.2f}")
def deposit():
amount = float(input("Enter an amount to be deposited: "))
if amount < 0:
print("Invalid amount. Please enter a positive number.")
return 0
else:
return amount
def withdraw(balance):
amount = float(input("Enter an amount to withdraw: "))
if amount < 0:
print("Invalid amount. Please enter a positive number.")
elif amount > balance:
print("Insufficient funds.")
else:
balance -= amount
return balance
balance = 0
is_running = True
while is_running:
print("Welcome to the Bank")
show_balance(balance)
print("2. Deposit")
print("3. Withdraw")
print("4. Exit")
choice = input("Enter your choice: ")
if choice == "1":
show_balance(balance)
elif choice == "2":
balance += deposit()
elif choice == "3":
balance = withdraw(balance)
elif choice == "4":
is_running = False
else:
print("Invalid choice. Please try again.")