The Noobs of Python: Exercise 1

Exercise 1 - Mad Libs Generator

So we already had a few tutorials by @Miguel_Sensacion but for me working through some examples individual examples was not enough. I've tried to use all knowledge from few episodes and put something together but didn't want to spam individual episodes with non relevant code. I've searched web for various examples of things i could do with python and here is what I've found and successfully completed the assignment. This thread could be more mesy than regular Episode threads and community will be able to help you if you're having problem with completing your assignment :wink:


The Goal:

The program will first prompt the user for a series of inputs a la Mad Libs. For example, a singular noun, an adjective, etc. Then, once all the information has been inputted, the program will take that data and place them into a premade story template. You’ll need prompts for user input, and to then print out the full story at the end with the input included.
Concepts to keep in mind:

  • Strings
  • Variables
  • Concatenation
  • Print

A pretty fun beginning project that gets you thinking about how to manipulate user inputted data. This project focuses far more on strings and concatenating. Have some fun coming up with some wacky stories for this!

[Update]
Tutorials that will be usefull for this exercise will be:
Introduction
and
Strings
If you want to make your program more advanced you can also go to:
Lists
and
Dictionaries
Also to find all tutorials just search for #noobsofpython tag

3 Likes

Please first try to create your program without looking at the example

Here is my very basic Star Wars Mad Libs:

Code

#!/usr/bin/python3

# Star Wars Mad Libs

from time import sleep

# Welcome message
print('Welcome to our Star Wars mad libs generator. Please type words below')

# sleep for 1 sec
sleep(1)

# assign inputs to variables
name = input('Name:  ')
adjective_1 = input('Adjective:  ')
verb_1 = input('Verb:  ')
silly_word= input('Silly Word:  ')
noun_1= input('Noun:  ')
noun_2_plu= input('Noun (plurar):  ')
verb_2_end_ed= input('Verb ending in "ed":  ')
noun_3 = input('Noun:  ')
noun_4 = input('Noun:  ')
verb_3_end_ed = input('Verb ending in "ed":  ')
adjective_2 = input('Adjective: ')

# sleep for 1 sec
sleep(1)

# print your mad libs output
print("""


""")


print('Darth', name, 'looked at his master while his', adjective_1, 'breathing filled the room.')
print('He was told to go to',  verb_1, 'evrything on the planet of', silly_word, '. He got in his', noun_1, 'and jumped to hyperspace.')
print('Soon before he reached the planet, he dropped out of hyperspace and was attacked by Rebel', noun_2_plu, '. ')
print('He', verb_2_end_ed, 'them off and continued to the planet`s surface. He landed and confronted more opposition, slicing it down with his', noun_3, '.')
print('He used the', noun_4, 'to choke another Rebel, then', verb_3_end_ed,  'him aside. He finished off all life on the planet with a/an', adjective_2, 'laugh.')
1 Like