After, getting the word length from the user,its time for getting the word of exact same length as given by the user from the database!
Its time to look into our third function that is the get display word function.
Without further wasting time let's get into the code..
CODE:
def get_display_word(word, idxs):
As we can, here we have used the enumerate function we had looked into earlier. Here, we will check the word length enter by the user and the word in our database and choose a random word for the game. After choosing the random the word it will display the strip of unfilled spaces to be filled in!
Looks interesting right? Well, there is another function which is going to help user to solve with more ease! Let's look into that some other day, until then sit tight and keep learning!
- Shreya Uttarwar
(L-69)
Its time to look into our third function that is the get display word function.
Without further wasting time let's get into the code..
CODE:
def get_display_word(word, idxs):
"""Get the word suitable for display."""
if len(word) != len(idxs):
raise ValueError('Word length and indices length are not the same')
displayed_word = ''.join(
[letter if idxs[i] else '*' for i, letter in enumerate(word)])
return displayed_word.strip()
As we can, here we have used the enumerate function we had looked into earlier. Here, we will check the word length enter by the user and the word in our database and choose a random word for the game. After choosing the random the word it will display the strip of unfilled spaces to be filled in!
Looks interesting right? Well, there is another function which is going to help user to solve with more ease! Let's look into that some other day, until then sit tight and keep learning!
- Shreya Uttarwar
(L-69)
Nice work!!
ReplyDeleteThank you!!
DeleteThis comment has been removed by the author.
ReplyDeleteGood explanation. Keep writing
ReplyDeleteThank you...
Delete