Assignment 2 – Mad Libs Story

Write a Python program that creates and uses variables of different types. Get and store input from the user. Output information including escape characters.

Assignment Description

Create your own Mad Libs story. The idea of the Mad Libs game is to write down different words that fit parts of speech, and then incorporate those words into a prewritten story.

Steps

  1. In PyCharm (Community Edition), open your existing ITP115 project.
  2. Under the Assignments directory, create a new directory called a2_last_first where last is your last/family name and first is your preferred first name. Use all lowercase letters.
  3. In the directory, create a new Python file called assignment2.py.
  4. At the top of the file, put comments in the following format and replace the name, email, and section with your actual information:


# ITP 115, Fall 2022
# Section: number or nickname
# Assignment 2
# Description:
# Describe what this program does such as:
# This program creates a Mad Libs story.
# It gets input from the user and prints output.

  1. Use the input() function to user input for the following input and store them in variables:

o 5 strings (str)
o 3 integers (int)
o 1 floating point number (float)

This content is protected and may not be shared, uploaded, or distributed.

ITP 115 2022-08-21

o Name the variables whatever you want, but use good coding practice.

o You can get more user input if you want.

o The strings need to be different parts of speech such as a noun, verb, adjective, adverb, or preposition. You can also ask for a special type of the part of speech, such as a place (“Disneyland”), a proper name (“Khurram”), or a color.

  1. At least two of the values entered must be in used in some mathematical calculation (e.g. adding, multiplying, etc.), and the result should be used in the story. Make sure to use the int() and float() functions to convert the strings entered by the user to the appropriate number type.
  2. Your program must then print out the story with the user’s words injected into the story. You may use multiple print() statements. If you do not use multiple print() statements, then use the new line escape character to print on multiple lines.
  3. Signify to the user their input in the story using “” (e.g. “chicken” or “42”). To do this, use escape characters. In other words, when the story is printed, the values of the variables will be surrounded by quotes.
  4. Since there will quotation marks around the words, follow proper formatting and ensure there are no extra spaces (e.g. “42”, not ” 42 “).

10.Create your own story. Do not use the story in the Sample Output.

11.Be sure to comment your code. This means that there should be comments throughout your code. Generally, a comment for every section of code explaining what it does. Points will be deducted for not having comments.

12.Follow coding conventions.

13.Test the program. Look at the Sample Output below. Assignments that do not run are subject to 20% penalty.

14.Prepare your submission:
o Find the a2_last_first folder on your computer and compress it. This cannot be

done within PyCharm.

o On Windows, use File Explorer to select the folder. Right click and select the Send to -> Compressed (zipped) folder option. This will create a zip file.

o On Mac OS, use Finder to select the folder. Right click and select the Compress “FolderName” option. This will create a zip file.

Page 2 of 4

ITP 115

2022-08-21

15.Upload the zip file to your Blackboard section:
o On Blackboard, navigate to the appropriate item.
o Click on the specific item for this assignment.
o Click on the Browse Local Files button and select the file. o Click the Submit button.

Grading

  •  This assignment is worth 25 points.
  •  Make sure that you the program runs. Points will be taken off if the graders have to

edit the source code to test your program.

  •  Make sure to submit your assignment correctly as described above. Points will be taken off for improper submission.

Item Points

Reading in each individual input (9) 9

Mathematical calculation 2

User input is in the story with surrounding quotes 9

Comments, style, and proper submission 5

Total

25

Page 3 of 4

ITP 115
Sample Output

Enter an animal (plural): sloths

Enter an adjective: funny

Enter another adjective: hungry

Enter a verb: fly

Enter a verb ending in ‘ing’: playing chess Enter a number: 3
Enter a second number: 10
Enter a third number: 4

Enter a number with a decimal: 3.2

2022-08-21

Today I adopted “3” pet “sloths”.
I learned that each animal needs “3.2” hours of “playing chess” every day, and that they travel in groups of “4”.
They are so “funny” that I decided to adopt “10” more.
Now I have “13” “sloths” and I am so “hungry” that I want to “fly”.

Page 4 of 4

 


    Customer Area

    Make your order right away

    Confidentiality and privacy guaranteed

    satisfaction guaranteed