In today's post we're going to have a look on the functions which constitute the working of this game.
So,the first function we are writing is to "get the no.of attempts"
Here, the user is getting the choice to have as much as 5 chances to solve the puzzle. Interesting,right? Let's get into the code part!
CODE:
As you can see, we have also taken care of the error that would occur if the attempts exceed 5,awesome!
There are still some more functions to be discussed, so make sure you visit our blog for the next post!
Till,then keep learning and stay home,stay safe :-)
-Kartik Mehetre (L-47)
So,the first function we are writing is to "get the no.of attempts"
Here, the user is getting the choice to have as much as 5 chances to solve the puzzle. Interesting,right? Let's get into the code part!
CODE:
def get_num_attempts():
"""Get user-inputted number of incorrect attempts for the game."""
while True:
num_attempts = input('How many incorrect attempts do you want? [1-5] ')
try:
num_attempts = int(num_attempts)
if 1 <= num_attempts <= 5:
return num_attempts
else:
print('{0} is not between 1 and 5'.format(num_attempts))
except ValueError:
print('{0} is not an integer between 1 and 5'.format(num_attempts))
As you can see, we have also taken care of the error that would occur if the attempts exceed 5,awesome!
There are still some more functions to be discussed, so make sure you visit our blog for the next post!
Till,then keep learning and stay home,stay safe :-)
-Kartik Mehetre (L-47)
Comments
Post a Comment