So, here comes the last one and the user's function, here, in this function we will look into how user will be given hints to solve the puzzle and how the solving will go and how he/she won't be able to cheat!
Let's jump directly into the code and see how that will happen:
CODE:
def get_next_letter(remaining_letters):
Now, in this we can see that first we will take the user inputted letters and the user will use these letters to fill in these spaces. As soon as the user inputs correct letter all the spaces with that letters will be filled. Then, if user tries to cheat by inputting 2 letters in single go then, the message will be displayed that the inputted letter is not a single character and his one life will be taken away, if user enters special character then also it will display the message and the last if user has used one letter out of 26 alphabets then he cannot use that letter again! that's is helping right?:)
So, now there is only main function remaining, we'll look into that someday later! Till then have a good day!
- Shreepad Sapate(L-60)
Let's jump directly into the code and see how that will happen:
CODE:
def get_next_letter(remaining_letters):
"""Get the user-inputted next letters."""
if len(remaining_letters) == 0:
raise ValueError('There are no remaining letters')
while True:
next_letter = input('Choose the next letter: ').lower()
if len(next_letter) != 1:
print('{0} is not a single character'.format(next_letter))
elif next_letter not in ascii_lowercase:
print('{0} is not a letter'.format(next_letter))
elif next_letter not in remaining_letters:
print('{0} has been guessed before'.format(next_letter))
else:
remaining_letters.remove(next_letter)
return next_letter
Now, in this we can see that first we will take the user inputted letters and the user will use these letters to fill in these spaces. As soon as the user inputs correct letter all the spaces with that letters will be filled. Then, if user tries to cheat by inputting 2 letters in single go then, the message will be displayed that the inputted letter is not a single character and his one life will be taken away, if user enters special character then also it will display the message and the last if user has used one letter out of 26 alphabets then he cannot use that letter again! that's is helping right?:)
So, now there is only main function remaining, we'll look into that someday later! Till then have a good day!
- Shreepad Sapate(L-60)
Very well explained! Great job!!
ReplyDeleteUser friendly indeed!
ReplyDeleteVery informative!
ReplyDeleteThanks!
DeleteKnowledgable
ReplyDeleteNice work.....great read
ReplyDeleteNice and easily understandable
ReplyDelete