Issue
I have a problem with my hangman project. When matching user input (lower case) with the word to guess (upper case), I'm using .upper which is causing an error.
if user_input.upper in self.word_to_guess:
indexes = self.find_indexes(user_input)
self.update_progress(user_input, indexes)
# If there is no letter to find in the word
if self.game_progress.count('_') == 0:
print('\n¡Yay! You win!')
print('The word is: {0}'.format(self.word_to_guess))
quit()
and I test that .upper change <class 'str'> to <class 'builtin_function_or_method'>
M = 'me'
print(M)
print(type(M))
print('')
M =(M.upper)
print(str(M))
print(type(M))
print('')
result
me
<class 'str'>
<built-in method upper of str object at 0x00007FFA191B1200>
<class 'builtin_function_or_method'>
I can convert those words to lowercase. However, I need to know how to use .upper() to change only 'me' to 'ME', without changing it into a class.'builtin_function_or_method'
Solution
You are not calling the method, but referencing it instead.
By doing M.upper
you are making M equal to the upper method instead of actually running it.
M.upper()
will run the method and return the result
Answered By - Leo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.