| CMSC 201 |
Lab 5: Functionslab5.py
#Function: getWordList(wordType)
#Input: list of required types of words
#Output: list of words to put into story
def getWordList(wordType):
wordList = []
#use a loop and the wordType parameter to ask the user for words
#and store the words in the word type list
return wordList
#Function: fillStory(wordList,storyList)
#Input: list of words to fill in story blanks
#Output: completed story as a list
def fillStory(wordList,storyList):
#maybe put a for loop here?
#try using end="" for some of your print statements
#your storyList has one more entry than you wordList
#so maybe an if statement here?
def main():
#declare the story variables
wordReqList = ["boy\'s name","noun","enter the same noun","occupation","unit of measurement", "noun", "adjective","game","adjective","game (preferably the same as before) ", "p\
lural noun","verb ending in -ing"]
storySentences = ["On his 11th birthday, young "," Potter discovers the ", " he never knew he had,\n the ", " of a/an ", ". In his first "," at Hogwarts School of Witchcraft and ",",\
he meets his two "," friends Ron Weasley, an expert at Wizard ", ", and Hermione \n Granger, a girl with "," parents. Harry learns the game of Quiditch and Wizard \n", " on his way to facing a Dark ", "\
teacher who is bent on ", " him. \n"]
#greeting
print("Welcome to MadLibs!")
print("Story Title: Harry Potter")
#read in input using getWordList
storyWords = getWordList(wordReqList)
#print out the story
fillStory(storyWords, storySentences)
main()
|