Skip to content

Commit 28690ce

Browse files
Add signature for guesses_exceeded and doctest
1 parent 91c5e1f commit 28690ce

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

cse231/number_guessing_game.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,39 @@ def player_progress(num_of_guesses, user_guess, correct_digits, correct_pos_digi
101101

102102
def success_message(num_of_guesses):
103103
"""
104-
If user guesses number successfully, print how many guesses were used.
104+
If user guesses the secret number successfully,
105+
show how many guesses were used.
105106
106107
:param num_of_guesses: int
107108
108109
>>> success_message(5)
109110
Congratulations! You have successfully guessed the secret number!
110111
It took you 5 guesses to get it right!
111112
"""
113+
112114
print('Congratulations! You have successfully guessed the secret number!')
113115
print('It took you {} guesses to get it right!'.format(num_of_guesses))
114116

115117

118+
def guesses_exceeded(allowed_guesses, num_of_guesses):
119+
"""
120+
Set the maximum number of guesses and notify the user
121+
that they lost when they exceed the limit.
122+
123+
:param allowed_guesses: int
124+
:param num_of_guesses: int
125+
126+
>>> guesses_exceeded(5, 6)
127+
Allowed guesses: 5
128+
Used guesses: 6
129+
You have exceeded your limit of guesses, you lose!
130+
"""
131+
132+
print('Allowed guesses: {}'.format(allowed_guesses))
133+
print('Used guesses: {}'.format(num_of_guesses))
134+
print('You have exceeded your limit of guesses, you lose!')
135+
136+
116137
if __name__ == '__main__':
117138
import doctest
118139

0 commit comments

Comments
 (0)