-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
116 lines (87 loc) · 3.09 KB
/
main.py
File metadata and controls
116 lines (87 loc) · 3.09 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#Basic Python Banking Project
import sys
balance = 0
def main():
while True:
try:
print("************************************************************")
print("1. Show Balance")
print("2. Deposit")
print("3. Withdraw")
print("4. Exit")
print("************************************************************")
user_start = int(input("Welcome to the Bank Manager! Please select an Action above: "))
if user_start == 1:
print(show_balance())
elif user_start == 2:
deposit()
elif user_start == 3:
withdraw()
elif user_start == 4:
exiting()
else:
print("Invalid input! Please enter a number 1-4.")
main()
except ValueError:
print("Invalid input! Please enter a number 1-4.")
main()
def show_balance():
print("**********************************")
print(f"Your Bank Balance is {round(balance, 2)}.")
print("**********************************")
restarting()
def deposit():
global balance
try:
dep_amount = float(input("How much would you like to deposit?: "))
if dep_amount <= 0:
print("Deposit amount must be greater than 0. Please try again.")
deposit()
else:
dep_amount = round(dep_amount, 2)
balance += dep_amount
print(f"You have deposited {dep_amount:.2f} and your new balance is {balance:.2f}")
restarting()
except ValueError:
print("Invalid input! Please enter a numeric value.")
deposit()
def withdraw():
global balance
try:
with_amount = float(input("How much would you like to withdraw? If you would like to go back enter 0: "))
if with_amount < 0:
print("Withdrawal amount must be greater than 0. Please try again.")
withdraw()
elif balance >= with_amount and with_amount!= 0:
balance -= with_amount
print(f"Withdrawal successful! Your new balance is: {balance:.2f}")
restarting()
elif with_amount == 0:
main()
else:
print("Invalid Withdrawal Amount! Insufficient balance.")
withdraw()
except ValueError:
print("Invalid input! Please enter a numeric value.")
withdraw()
def exiting():
print("Thanks for using the Bank Manager! Goodbye")
sys.exit()
def restarting():
try:
restart = True
while restart:
restart_pro = int(input("Press 1 to return and select another action or press 2 to exit: "))
if restart_pro == 1:
restart = False
main()
elif restart_pro == 2:
restart = False
exiting()
else:
print("Sorry that is an invalid input please try again")
restarting()
except ValueError:
print("Sorry that is an invalid input please try again")
restarting()
main()