Letter Guessing Game In Python
I'm attempting to code a basic letter game in python. In the game, the computer moderator picks a word out of a list of possible words. Each player (computer AI and human) is shown
Solution 1:
Number of characters in the word: len()
function
In [15]: len('jabberwocky')
Out[15]: 11
An example of a mask:
In [16]: mask = ' '.join(('_' for i in range(len('jabberwocky'))))
In [18]: mask
Out[18]: '_ _ _ _ _ _ _ _ _ _ _'
# j a b b e r w o c k y
References on everything involved in the mask example:
str.join()
method.range()
built-in function.- generator expressions (used to generate N underscores).
All in all, what it does is:
- Count the characters in the word 'jabberwocky'
- Generate n underscores
- Join them by a space.
Solution 2:
On a cursory analysis of your project, I believe you can find all the answers you need in the Python documentation. Addressing your first question, see here:
http://docs.python.org/3.2/library/functions.html#len
Addressing future questions that you may have as you need to deal with strings, see here: http://docs.python.org/3.2/tutorial/introduction.html#strings
Post a Comment for "Letter Guessing Game In Python"