-
Notifications
You must be signed in to change notification settings - Fork 1
/
lesson-10.py
executable file
·43 lines (36 loc) · 883 Bytes
/
lesson-10.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
#!/usr/bin/env python3
# lesson-10.py - allow unlimited transactions
#
# Learn:
# looping
# break out of a loop
# Boolean literal
# single-branch conditional statement
def showBalance():
global balance
print('Your balance is $%d.' % balance)
print()
def withdrawal(amount):
global balance
print('Withdraw $%d.' % amount)
balance -= amount
showBalance()
def deposit(amount):
global balance
print('Deposit $%d.' % amount)
balance += amount
showBalance()
def main():
print('Welcome to the bank.')
showBalance()
while True:
type = input('Enter d for deposit, w for withdrawal, or q to quit: ')
if type == 'q':
break
amount = int(input('Enter amount: '))
if type == 'd':
deposit(amount)
else:
withdrawal(amount)
balance = 100
main()