forked from hacktoberfest17/programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatm.py
More file actions
30 lines (27 loc) · 744 Bytes
/
Copy pathatm.py
File metadata and controls
30 lines (27 loc) · 744 Bytes
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
#!/usr/bin/env python
try:
input = raw_input
except:
pass
def dispense(x):
if x <= 0 or x % 10 or x in (10, 30):
raise KeyError
q = x // 50
if (x - 50 * q) % 20:
q -= 1
return tuple([q, (x - q * 50) // 20])
while True:
try:
amt = dispense(int(input('Enter amount to turn into $20 and $50 notes: ')))
msg = ''
if amt[0]:
msg += '%s x $50' % amt[0]
if amt[0] and amt[1]:
msg += ', '
if amt[1]:
msg += '%s x $20' % amt[1]
print(msg)
except (KeyError, ValueError):
print('Invalid amount. Must be able to make up the total using $20 and $50 notes.')
except (KeyboardInterrupt, EOFError):
break