-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathexample.py
More file actions
42 lines (32 loc) · 1.05 KB
/
example.py
File metadata and controls
42 lines (32 loc) · 1.05 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
# https://codevscolor.com/python-bank-account-class
class Bank:
def __init__(self):
self.total_amount = 0
self.name = ''
def welcome(self):
self.name = input('Welcome to your Bank Account. Please Enter your name: ')
def print_current_balance(self):
print('Your Current balance : {}'.format(self.total_amount))
def deposit(self):
self.total_amount += float(input('Hello {}, please enter amount to deposit: '.format(self.name)))
self.print_current_balance()
def withdraw(self):
amount_to_withdraw = float(input('Enter amount to withdraw: '))
if amount_to_withdraw > self.total_amount:
print('Insufficient Balance !!')
else:
self.total_amount -= amount_to_withdraw
self.print_current_balance()
if __name__=="__main__":
bank = Bank()
bank.welcome()
while True:
input_value = int(input('Enter 1 to see your balance,\n2 to deposit\n3 to withdraw\n'))
if input_value == 1:
bank.print_current_balance()
elif input_value == 2:
bank.deposit()
elif input_value == 3:
bank.withdraw()
else:
print('Please enter a valid input.')