Question: # MadLibs from a file using python def madlib_word(word): Returns a substitution for a fill-in-the-blank or the original word. if word[0] == _ == word[-1]:

 # MadLibs from a file using python def madlib_word(word): """Returns a

# MadLibs from a file

using python

def madlib_word(word): """Returns a substitution for a fill-in-the-blank or the original word.""" if word[0] == "_" == word[-1]: return input(word[1:-1].replace("_", " ")+'? ') else: return word

def madlib_line(text): """Returns a string containing the line with the fill-in-the-blanks substituted.""" words = text.split() # try printing this to see what it does # process all the words in the line and return a string - hint use madlib_word return def madlib_file(filename): """Reads the madlib file and returns the completed madlib as a list of strings.""" # process all the lines in the file and return a list of strings - hint use madlib_line return def madlib_print(madlib): """Prints a completed MadLib, line by line.""" # print the strings in the list return def main(): """Completes the user supplied madlib.""" filename = input("MadLib filename? ") madlib_print(madlib_file(filename))

# Do not change the following lines or the tests will fail. if __name__ == '__main__': main()

MadLib filename? name? noun? an event? Frank is too cool for Python class. Instead, they will be attending concert Your solution should contain the following functions: 1. madlib_word (word) -An implementation of this function is already given. This function replaces the blanks in madlib with given word. 2. madlib_line (text) - This function should make a cal1 to madlib_word function for building a sentence/line constituting the words. 3. madlibfile(filename) - This function should make a call to madlib_line to build each sentence of the given mad1b and should write each ne built in above step to the given madb filename 4. madlib_print (madlib) - Should print a completed madlib from the given madlib file. MadLib filename? name? noun? an event? Frank is too cool for Python class. Instead, they will be attending concert Your solution should contain the following functions: 1. madlib_word (word) -An implementation of this function is already given. This function replaces the blanks in madlib with given word. 2. madlib_line (text) - This function should make a cal1 to madlib_word function for building a sentence/line constituting the words. 3. madlibfile(filename) - This function should make a call to madlib_line to build each sentence of the given mad1b and should write each ne built in above step to the given madb filename 4. madlib_print (madlib) - Should print a completed madlib from the given madlib file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!