-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathBank1_OneAccount.py
77 lines (60 loc) · 2.26 KB
/
Bank1_OneAccount.py
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
# Non-OOP
# Bank Version 1
# Single account
accountName = 'Joe'
accountBalance = 100
accountPassword = 'soup'
while True:
print()
print('Press b to get the balance')
print('Press d to make a deposit')
print('Press w to make a withdrawal')
print('Press s to show the account')
print('Press q to quit')
print()
action = input('What do you want to do? ')
action = action.lower() # force lowercase
action = action[0] # just use first letter
print()
if action == 'b':
print('Get Balance:')
userPassword = input('Please enter the password: ')
if userPassword != accountPassword:
print('Incorrect password')
else:
print('Your balance is:', accountBalance)
elif action == 'd':
print('Deposit:')
userDepositAmount = input('Please enter amount to deposit: ')
userDepositAmount = int(userDepositAmount)
userPassword = input('Please enter the password: ')
if userDepositAmount < 0:
print('You cannot deposit a negative amount!')
elif userPassword != accountPassword:
print('Incorrect password')
else: #OK
accountBalance = accountBalance + userDepositAmount
print('Your new balance is:', accountBalance)
elif action == 's': # show
print('Show:')
print(' Name', accountName)
print(' Balance:', accountBalance)
print(' Password:', accountPassword)
print()
elif action == 'q':
break
elif action == 'w':
print('Withdraw:')
userWithdrawAmount = input('Please enter the amount to withdraw: ')
userWithdrawAmount = int(userWithdrawAmount)
userPassword = input('Please enter the password: ')
if userWithdrawAmount < 0:
print('You cannot withdraw a negative amount')
elif userPassword != accountPassword:
print('Incorrect password for this account')
elif userWithdrawAmount > accountBalance:
print('You cannot withdraw more than you have in your account')
else: #OK
accountBalance = accountBalance - userWithdrawAmount
print('Your new balance is:', accountBalance)
print('Done')