Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am real lost on my python program and I do not not where to go next. Here is my code: Here is the grader
I am real lost on my python program and I do not not where to go next.
Here is my code:
Here is the grader feedback.
8.10 A8 Program Let's write a program that can handle any Madlib. To do that we will read the Madlib from a file. The MadLib will contain words like_name, or_a_place_ which identify the blanks that must be filled in. Your program should prompt the user for a substitution for each blank in the file before printing the resulting Madlib. Some code is provided to get you started. There are also comments to guide you Sample Input There are four sample files for you to test your program. You can download these files below madlib1 madlib2 madlib3 madlib4 The contents of the madlib4 file are name_ is too cool for _noun_ class Instead, they will be attending _an_event Note that there are spaces surrounding each_blank_in the input file to simplify parsing them. The same input for the program includes the filename, followed by the values for the_blanks_. Here is some sample input for madlib4. madlib4 Frank Python concert Sample Output The output for the madlib4 file should look like this when given the sample input above. 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 the blanks in madlib with given word. is already given. This unction replaces 2. madlib_line (text)-This function should make a call to madlib_word function for building a sentence/line constituting the words. 3. madlib_file(filename) -This function should make a call to madlib_line to build each sentence of the given madlib and should write each line built in above step to the given madlib filename 4. madlib_print (madlib) - Should print a completed madlib from the given madlib file. # MadLibs from a file 2 madlib word word) "Returns a substitution for a fill-in-the-blank or the original word.""" if word [0]" word [-1]: 4 return input (word [1:-1].replace("_", " ")+'71n' 7 else: return word 10 def madlib_line(text): "Returns a string containing the line with the fill-in-the-blanks substituted." 12 13 14 15 16 17 18 19 20 21 words-text. split() # try printing this to see what it does for word in words: # process all the words in the line and return a string-hint use madlib word s mad_lib(word) return S def madlib_file(filename): Reads the madlib file and returns the completed madlib as a list of strings."m with open(filename) as f: 23 24 25 26 27 28 29 30 xf.readlines () f.close) # process all the lines in the file and return a list of strings-hint use madlib Line return x def madlib_print(madlib): "Prints a completed MadLib, line by line.""n for line in madlib: 32 print(line) # print the strings in the list 35 36 37 38 39 40 41 42 43 mainO def main) iCompletes the user supplied madLib."n filename input ("MadLib filename? ") madlib_print(madlib_file(filename) ) Output differs. See highlights below madlib1 2 Input 4 MadLb fliename ? ear name ou are adverb invited! -name-is having a theme-party! It's going to be at a place_ on _day_of_the_week Please make sure you show up on time, or else you will be required to _verb_ a/an _animal_ with your _body_part_. Your output MadLib filename? name2 adverb? name? theme? a place? day of the week? time? verb? animal? body part? Dear 0 You are invited! Expected output is having a 3 party! It's going to be at 4 on 5 . Please make sure you show up on 6 , or else you will be required to 7 a/an 8 with your 9Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started