Mad Libs Generator | Rookie Week of Python Day 03
Mad libs generator is a fun game that is usually played by kids. In this python game user has to enter substitutes for blanks in the story without knowing the story. It is a fun and creative way to see what stories people come up with.
Mad Libs Generator
We will declare a variable loop
and initialize it with the value of 1
.
loop = 1
We will then create a while
loop and increment the loop
variable till it reaches 10
while (loop < 10):
We need some inputs from the user. We will be requiring 2 nouns, 1 plural noun, 1 place, and 1 adjective for our specific Mad Libs Paragraph.
while (loop < 10):
noun = input("Choose a noun: ")
p_noun = input("Choose a plural noun: ")
noun2 = input("Choose a noun: ")
place = input("Name a place: ")
adjective = input("Choose an adjective (Describing word): ")
noun3 = input("Choose a noun: ")
Now to output our paragraph with the user entered variables in the appropriate spaces.
while (loop < 10):
noun = input("Choose a noun: ")
p_noun = input("Choose a plural noun: ")
noun2 = input("Choose a noun: ")
place = input("Name a place: ")
adjective = input("Choose an adjective (Describing word): ")
noun3 = input("Choose a noun: ")
print ("------------------------------------------")
print ("Be kind to your",noun,"- footed", p_noun)
print ("For a duck may be somebody's", noun2,",")
print ("Be kind to your",p_noun,"in",place)
print ("Where the weather is always",adjective,".")
print ()
print ("You may think that is this the",noun3,",")
print ("Well it is.")
print ("------------------------------------------")
To loop the program back to the initial position we can add redefine the value of the loop
variable within the while statement.
loop = loop + 1
Output
Feel free to make it as crazy as you like. Remember to have fun.
If you want to get started you can fork this code from GitHub here