-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram1.py
More file actions
51 lines (43 loc) · 1.28 KB
/
program1.py
File metadata and controls
51 lines (43 loc) · 1.28 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
import sys
money = sys.argv[1]
def moneyCount(amount):
#calculates the amount of dollars, quarters, dimes, nickels, and pennies needed
global money
money = money.split('.')
try:
dollars = int(money[0])
if dollars > 0:
print(dollars, ' dollars')
except:
print('please provide a dollar amount')
return
try:
cents = int(money[1])
quarters = cents//25
cents %= 25
dimes = cents//10
cents %= 10
nickels = cents//5
cents %= 5
pennys = cents
coins = [quarters,dimes,nickels,pennys]
for coin in coins:
if coin != 0:
print
if quarters != 0:
print(quarters, " quarters")
if dimes != 0:
print(dimes, " dimes")
if nickels != 0:
print(nickels, " nickels")
if pennys != 0:
print(pennys, " pennys")
except:
print('please provide a cent amount')
return
return
if money[0] == '$':
money = money.replace('$', '')
moneyCount(money)
else:
print('string must have $ as its first character \nsome terminals may eat the $ sign, in which case please use \$ instead')