MCPcopy Create free account
hub / github.com/ActiveState/code / start

Method start

recipes/Python/578988_Money_Game/recipe-578988.py:21–71  ·  view source on GitHub ↗

Randomly display an amount of change and ask how many of each coin type are needed to equal the amount displayed.

(self)

Source from the content-addressed store, hash-verified

19 print('*' * 75)
20
21 def start(self):
22 """Randomly display an amount of change and ask how many of each coin
23 type are needed to equal the amount displayed.
24 """
25 self.display_intro()
26 currency_amt = random.randint(1, 99)
27 print('\nHow much change is needed to equal .{0} cents?\n'
28 .format(str(currency_amt)))
29 your_total_amt = get_input_values(currency_amt)
30
31 if sum(your_total_amt) == 0:
32 print('Thank you for playing.')
33 sys.exit(0)
34 else:
35 if your_total_amt[0] > 1 or your_total_amt[0] == 0:
36 quarter_spelling = 'quarters'
37 else:
38 quarter_spelling = 'quarter'
39
40 if your_total_amt[1] > 1 or your_total_amt[1] == 0:
41 dime_spelling = 'dimes'
42 else:
43 dime_spelling = 'dime'
44
45 if your_total_amt[2] > 1 or your_total_amt[2] == 0:
46 nickel_spelling = 'nickels'
47 else:
48 nickel_spelling = 'nickel'
49
50 if your_total_amt[3] > 1 or your_total_amt[3] == 0:
51 penny_spelling = 'pennies'
52 else:
53 penny_spelling = 'penny'
54
55 print('\nCorrect! You entered {0:d} {1}, {2:d} {3},'
56 ' {4:d} {5} and {6:d} {7}.'.format(your_total_amt[0],
57 quarter_spelling,
58 your_total_amt[1],
59 dime_spelling,
60 your_total_amt[2],
61 nickel_spelling,
62 your_total_amt[3],
63 penny_spelling))
64 print('Which equals .{0} cents. Nice job!'
65 .format(str(currency_amt)))
66
67 response = input('\nWould you like to try again? ')
68 if response.lower() != 'y':
69 print('Thanks for playing.')
70 sys.exit(0)
71 self.start()
72
73
74def get_input_values(currency_amt):

Callers 15

process_requestMethod · 0.45
get_urlMethod · 0.45
convertMethod · 0.45
downloadMethod · 0.45
runCallbackEventsMethod · 0.45
echo_serverMethod · 0.45
start_searchMethod · 0.45
begin_rmMethod · 0.45
recipe-579023.pyFile · 0.45
mainFunction · 0.45
recipe-578988.pyFile · 0.45
fetch_dataMethod · 0.45

Calls 8

display_introMethod · 0.95
printFunction · 0.85
strFunction · 0.85
get_input_valuesFunction · 0.85
sumFunction · 0.50
formatMethod · 0.45
exitMethod · 0.45
lowerMethod · 0.45

Tested by

no test coverage detected