Today, let's look into another function which constitutes the working of the game.
So, the second function we are going to see is to get the minimum word length from the user.
Here, user will enter his word preferred word length to increase his chances of winning and saving himself.
Lets get to the code part!
CODE:
def get_min_word_length():
As you can see, we are asking the user to choose the minimum which is from 2-16, and if the word length is not in between the range it will display the error message!
Looks easy right? Well, it is easy!
We still have more functions to discuss till then sit tight and keep learning!
-Shreepad Sapate(L-60)
So, the second function we are going to see is to get the minimum word length from the user.
Here, user will enter his word preferred word length to increase his chances of winning and saving himself.
Lets get to the code part!
CODE:
def get_min_word_length():
"""Get user-inputted minimum word length for the game."""
while True:
min_word_length = input(
'Choose minimum word length [2-16] ')
try:
min_word_length = int(min_word_length)
if 2 <= min_word_length <= 16:
return min_word_length
else:
print('{0} is not between 4 and 16'.format(min_word_length))
except ValueError:
print('{0} is not an integer between 4 and 16'.format(
min_word_length))
As you can see, we are asking the user to choose the minimum which is from 2-16, and if the word length is not in between the range it will display the error message!
Looks easy right? Well, it is easy!
We still have more functions to discuss till then sit tight and keep learning!
-Shreepad Sapate(L-60)
Comments
Post a Comment