>>> from WordGame import *
>>> import random
############################# Directions
#############################
The goal of this assignment is to create a
text based word guessing
game.
The project is completely described in this file,
WordGameTEST.py. Follow these steps:
1) download files to your working folder. you will need the win.txt
and lose.txt files as inputs
2) Create a file WordGame.py and add your solutions
(functions/classes) to that file.
3) After you finish each section, run the
doctest to check it.
4) When you are finished submit your WordGame.py
#################### clean
####################
clean - Implement a function clean that
accepts two str arguments, the
first a str of "bad" characters
and the second a phrase. clean
should then return a copy of the phrase
where each character in the bad
str has been replaced by a single space
character, " ".
>>> clean(".,?", 'Hello,
how are you?')
'Hello
how are you '
>>> bad =
'="0€%:@)795]”,(#-!3/;81?2&\'$.4*[6â'
>>> clean( bad, 'ACADEME, n. An
ancient school where morality and philosophy were taught.')
'ACADEME
n An ancient school where
morality and philosophy were taught '
>>> clean(bad, 'ACADEMY, n. [from
ACADEME] A modern school where football is taught.')
'ACADEMY
n from ACADEME A modern school where football is taught '
>>> clean(bad, bad) ==
len(bad)*" "
True
##>>> biercetxt =
clean(bad,open('Bierce.txt').read())
##>>> len(biercetxt)
##382251
#################### wordsByLength
####################
wordsByLength - Implement a function
wordsByLength that accepts one str
argument, a phrase, and that returns a
dictionary. Each key in the
returned dictionary is a word length and
the value corresponding to
that key will be a list of the words in the
phrase that have that
length.
Entries will be listed in the order encountered.
>>> wordsByLength('hello how are
you')
{5: ['hello'], 3: ['how', 'are', 'you']}
>>> wordsByLength('Given a phrase
this function will return a dictionary that lists those words by length')
{5: ['Given', 'lists', 'those', 'words'],
1: ['a', 'a'], 6: ['phrase', 'return', 'length'], 4: ['this', 'will', 'that'],
8: ['function'], 10: ['dictionary'], 2: ['by']}
##>>> wbl = wordsByLength(biercetxt)
##>>> [(k,len(wbl[k])) for k in
sorted(wbl)]
##[(1, 4147), (2, 11333), (3, 13065), (4,
9680), (5, 6628), (6, 5106), (7, 4663), (8, 3253), (9, 2877), (10, 1891), (11,
970), (12, 488), (13, 252), (14, 116), (15, 33), (16, 10), (17, 7)]
##>>> wbl[17]
##['controversialists',
'controversialists', 'contradistinction', 'objectionableness',
'WHANGDEPOOTENAWAH', 'Whangdepootenawah', 'Whangdepootenawah']
#################### WordGame
####################
WordGame - Implement a class WordGame that
is the basis for a guessing
game for words. A WordGame object has a secret word
inside. The
letters can be guessed using the guess
method and the game will keep
track of both the correct and incorrect
guesses that have been made as
well as the state of the game, i.e.,
whether still playing, won or lost.
Implementation methods/details:
__init__ - accepts one str argument, the
secret word. Note that the
secret word can be given in any case but
should be stored in UPPER case.
This method should create and initialize 3
attributes (ie., self.?????
):
-
str attribute to keep track of the secret word, initialized to the
given secret word (but converted to UPPER case).
-
str attribute to keep track of correct/right guesses, initialized
to an empty str.
-
str attribute to keep track of incorrect/wrong guesses,
Get Free Quote!
435 Experts Online