Mad Libs Game - Python Language

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 called mad_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

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.