Making a MadLib story¶
You might have done MadLib stories when you were a kid. You provide some pieces of information, like a name of a friend, a verb, and a favorite game (for example), and those pieces of information get plugged into a story. Since you don’t know the story beforehand, you’re surprised at what happens to your friend in the story.
-
csp-4-4-1: Now you want to add more to the story. You want it to say: “Pat called the
police who took the witch away.” Adding which of these lines to the end of
the program will make that happen? (Hint: It is okay to try each one!)
- real_ending = first_name + " called the police who took the witch away."
- This would only work if you also put
print(real_ending)
after this line. - print(first_name + " called the police who took the witch away.")
- This is a good way to do this since the line that is printed will have the correct first name. You could also make a string named
real_ending
first, and then print it. - print("Pat called the police who took the witch away.")
- This would work. But if you changed the
first_name
variable, this line would not change. A different answer is better.
You should really do this: Run this program to see what gets generated, then change some of the variables to make different stories. Try different names, different verbs.
- Yes
- The only thing that is different is when the lines are printed, but the lines are the same.
- No
- Did you try it? Copy the code into the program area above and run it.
csp-4-4-2: Would the following code print the same story as shown above?
first_name = "Sofia"
last_name = "Diaz"
gender = "girl"
address = "1600 Pennsylvania Avenue"
verb = "burp at"
start = "Once there was a " + gender + " named " + first_name + "."
print(start)
next1 = "A good " + gender + " living at " + address + "."
print(next1)
next2 = "One day, a wicked witch came to the " + last_name + " house."
print(next2)
next3 = "The wicked witch was planning to " + verb + " " + first_name + "!"
print(next3)
ending = "But " + first_name + " was smart and avoided the wicked witch."
print(ending)
- Mali is Mali
- There are no double quotes around the last Mali so it will use the value of the variable Mali.
- Mali is 5
- The first Mali is in double quotes so it will print the string Mali and the second Mali is not in double quotes so it will print the value of the variable Mali.
- 5 is Mali
- The first Mali is in double quotes and the second is not.
- 5 is 5
- The first Mali is in double quotes so it is a string and the characters in the string will be printed.
csp-4-4-3: What would the following code print?
Mali = 5
print("Mali" + " is " + str(Mali))
Note
When you print a string (a sequence of characters in a pair of single, double, or triple quotes) in Python it will print the exact characters in the string. When you print a variable it will print the value of that variable.
csp-4-4-5: csp-4-4-4: Put the blocks below into the correct order to print a twist on a famous
poem.print("Roses are red.")
---
print("Violets are blue.)
---
print("Sugar is sweet.")
---
print("And so is Sue.")
csp-4-4-7: csp-4-4-6: Put the blocks below into the correct order to declare the variables and
then print the following story. One day Jay went shopping. He wanted to
buy shoes. But, he didn't like any. So, Jay went home.name = "Jay"
item = "shoes"
---
print("One day " + name + " went shopping.")
---
print("He wanted to buy " + item + ".")
---
print("But, he didn't like any.")
---
print("So, " + name + " went home.")
Write the code below to calculate and print how many blocks you can travel in an hour if you walk .3 blocks every minute. It should print: “I will travel 18 blocks in an hour if I walk .3 blocks every minute.”
Name each of the values. Calculate the totalBlocks
it will take
and print the information.