-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleBankingSystem.py
More file actions
55 lines (42 loc) · 2.14 KB
/
SimpleBankingSystem.py
File metadata and controls
55 lines (42 loc) · 2.14 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
# William Starks
# proj4.py
# March 5, 2025
# A simple banking menu system for deposits, withdrawals, and repeating payments.
print("Enter starting balance:")
balance = float(input())
print("You have a balance of $" + format(balance, ",.2f"))
choice = ""
while choice != "q":
choice = input("Enter d for Deposit, w for Withdrawal, r for Repeating Payments, or q to Quit: ")
if choice == "d": # Deposit
deposit = -1
while deposit <= 0:
deposit = float(input("Enter deposit amount: "))
if deposit <= 0:
print("Deposit amount must be positive.")
balance += deposit
print("You deposited $" + format(deposit, ",.2f") + ". Your balance is now $" + format(balance, ",.2f"))
elif choice == "w": # Withdrawal
withdrawal = -1
while withdrawal <= 0:
withdrawal = float(input("Enter withdrawal amount: "))
if withdrawal <= 0:
print("Withdrawal amount must be positive.")
if withdrawal > balance:
print("You only have $" + format(balance, ",.2f") + " in your account and cannot withdraw $" + format(withdrawal, ",.2f") + ". Withdrawal denied.")
else:
balance -= withdrawal
print("You withdrew $" + format(withdrawal, ",.2f") + ". Your balance is now $" + format(balance, ",.2f"))
elif choice == "r": # Repeating Payments
payment = float(input("Enter payment amount: "))
num_payments = int(input("Enter number of payments: "))
total_cost = payment * num_payments
if total_cost > balance:
print("You only have $" + format(balance, ",.2f") + " but require $" + format(total_cost, ",.2f") + " to cover all payments. Repeating payments denied.")
else:
for i in range(1, num_payments + 1):
balance -= payment
print("Payment " + str(i) + " for $" + format(payment, ",.2f") + " made. Your balance is now $" + format(balance, ",.2f") + ".")
elif choice != "q":
print(choice + " is an invalid option")
print("Your balance is $" + format(balance, ",.2f") + ". Have a nice day!")