-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankingProgram.py
More file actions
55 lines (45 loc) · 1.26 KB
/
Copy pathBankingProgram.py
File metadata and controls
55 lines (45 loc) · 1.26 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
# shows balance of user
def showBalance(balance):
print(f"Your balance is ${balance:.2f}") # .2f adds a decimal and 2 numbers after decimal
# deposit money
def deposit():
amount = float(input("Enter amount to be deposited: "))
if amount < 0:
print("Not valid.")
return 0
else:
return amount
# withdraw money
def withdraw(balance):
amount = float(input("Enter amount to withdraw: "))
if amount > balance:
print("Insufficient funds")
return 0
elif amount < 0:
print("Amount must be greater than 0.")
return 0
else:
return amount
def main():
balance = 0
isRunning = True
while isRunning:
print("Banking Program")
print("1. Show Balance")
print("2. Deposit")
print("3. Withdraw")
print("4. Exit")
choice = input("Enter your choice (1-4): ")
if choice == "1":
showBalance(balance)
elif choice == "2":
balance += deposit()
elif choice == "3":
balance -= withdraw(balance)
elif choice == "4":
isRunning = False
else:
print("Not valid, please try again.")
print("Thank you, come again!")
if __name__ == "__main__":
main()