-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython301-finale-project.py
More file actions
56 lines (45 loc) · 1.75 KB
/
python301-finale-project.py
File metadata and controls
56 lines (45 loc) · 1.75 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
from fileinput import close
class BankUser():
def __init__(self, name):
self.name = name
self.file = f'{name}.txt'
# Creating the bank file of the current user
try:
open(f'{name}.txt', 'x').close()
except FileExistsError:
with open(self.file, 'w') as f:
f.write('')
# Makes the user Choose which action to do and with how much money
def bankAction(self):
action = ''
amount = 0
while not action:
action = input('Withdrawal or Deposit? (w/d) ').lower()
if action == 'w':
while not amount:
amount = float(input('How much would you like to withdraw? '))
if type(amount) is not float or amount <= 0:
print('Please enter a valid number')
amount = 0
else:
with open(self.file, 'a') as file:
file.write(f'-{amount}\n')
elif action == 'd':
while not amount:
amount = float(input('How much would you like to deposit? '))
if type(amount) is not float or amount <= 0:
print('Please enter a valid number')
amount = 0
else:
with open(self.file, 'a') as file:
file.write(f'+{amount}\n')
elif action == 'q':
action = True
else:
print('Please choose one of the options')
action = ''
with open(self.file, 'r') as f:
print(f.read())
sagi = BankUser('Sagi')
while True:
sagi.bankAction()