Mad Libs Game: Mad Libs game can be created by using string formatting method in python and extracting words from a text file.
Here is a sample code for Mad Libs game:
This code uses a function calledmad_libs()
that takes the name of a text file as an argument. The function opens the file, reads its content and split it into a list of words. Then it iterates through each word and checks if a word is enclosed in curly braces, it prompts the user to enter a word and replace the word in the list with the user entered word. Finally, it joins the list of words back into a string and returns the new text.Good Luck!
No comments:
Post a Comment