RESOURCES:
Class slides: https://docs.google.com/presentation/d/11UieHJcWcYvJy7hVcSUFgwp2mINhqcw71oD3T8qy-5s/edit?usp=sharing
Example code: https://replit.com/@ShravyaS/IntroToPython-5
(Notes included in example code.)
HOMEWORK:
For this project, please build a mad-lib generator. Mad-libs are stories where the user fills out some words, which are inserted into a (sort of) template. For this project, please allow users to choose between (at least) 3 story templates. Think of using .title() and .capitalize() "Enter the number 1 if you want the story about cheeseburgers, the number 2 if you want the story about Romeo and Juliet, and 3 if …"
https://madtakes.com/libs/152.html (example)
Write your answer as a comment, and we’ll post the solution by next class. See you then!
Note: VIP students, please contact us (Eric and me) about office hours!
print('If you want to hear the Madlib about Bob and his food, type 1 below. If you want the story about someone\'s birthday, type 2 below. If you want the Minecraft story, type 3 below.') story = int(input()) if story == 1: print('food') food = input() print('verb') action1 = input() print('random restaurant name') random_restaurant_name = input() print('verb') what_he_did_with_food = input() print('emotion') after_eating = input() print(f'Once upon a time, there was a time where there was a guy named Bob, and he wanted a {food}. "I\'m hungry," said Bob, "I want a {food}." So Bob {action1} over to his favorite restaurant: {random_restaurant_name}, to get his {food}. It took him forever to get his {food} because the drive-through line was so long. "Finally, one {food} please!" said Bob. "Coming right up sir." said the empolyee. He brought up Bob\'s {food} and yelled, "Next!". Bob {action1} home and {what_he_did_with_food} his {food}. "Wow!" he exclaimed, "I feel so {after_eating} after eating that {food}!"') if story == 2: print('boy name') name = input() print('age(PLEASE type your number like third, or fourth, or like first)') age = input() print('object') gift = input() print('random shop name') random_shop_name = input() print('verb') action2 = input() print('verb with an -ing') action3 = input() print(f'It was {name}\'s {age} birthday, and he wanted a {gift}. "I want a {gift}", he exclaimed. So {name} and his mom {action2} to {random_shop_name}, but couldn\'t find a(n) {gift}. so {name} pouted when he got home. it turns out {name}\'s dad bought his {gift} for him, so {name} didn\'t need to buy it. so {name} thanked his dad and un-wrapped the wrapping paper. he got out his new {gift} and started {action3} with it.') if g == 3: print('random name, like noob123') name = input() print('enemy name') e_name = input() print('verb ending with -ed') verbed1 = input() print('object') thing = input() print('minecraft spell or verb ending with -ed') verbed2 = input() print(f'Once in the minecraft world, there lived a hero named {name}. {name} was a mediocre hero and protected the villagers. Then one day, {e_name}, the enraged warrior, blasted the village wall with a TNT blaster. {e_name} yelled, "I challenge the great warrior, {name}!!!" {name} came forth, and was suddenly knocked unconscious. When {name} woke up, {name} was in a giant arena with lots of people around {name} and {e_name}, and none of the people were any of {name}\'s people. "Which weapon do you choose?!?" {name} chose an enchanted bow and arrow. {e_name} chose an netherite sword with fire aspect 2. It also wasn\'t fair for {name} because {name} didn\'t have armor but {e_name} did. The referee shouted, "GOOOOO!!!" {e_name} {verbed1} after {name}, and {name} ran from {e_name}, but {name} mustered all the courage {name} could and was about to shoot with the bow and arrow, when {name} tripped on a(n) {thing}, and shot the arrow high into the air...and into a chink in {e_name}\'s armor, and it turn\'s out the bow and arrow had {verbed2}, so {e_name} lost and died and respawned outside the ring."1,2,3! {name} wins!" the referee yelled. So {e_name} had to suffer the consequence for losing, and {name} received the trophy and went back home. The end.')
story1_title = "Happy Holiday"; story1_content_1 = "Hi I am" story1_content_2 = "and I am" story1_content_3 = "years old i love" story1_content_4 = "it is a great holiday I love it so so much my family loves it too and I love the" story1_content_5 = "so so much too and I don’t write much so I am done now bye bye" print('Please Select The Story You Want to Read (1-3) :'); story_choice = int(input()); story2_title = "Registering For Success" story2_content_1 = "Two weeks before " story2_content_2 = "’s class registration day at" story2_content_3 = "State University, she spent" story2_content_4 = "hours researching teachers and courses and making the" story2_content_5 = "schedule for her" story2_content_6 = "semester. On Monday," story2_content_7 = ", at exactly" story2_content_8 = ", Tasha logged on to register. She typed in the first class: registered. She typed in the second class: registered. The third class: class full. The fourth class: class not found. Tasha wished she had spent time making a plan" story2_content_9 = ". Oh well. Maybe she could finally try Floral Arranging for" story3_title = "Ted The Turkey" story3_content = "Hello, my name is" story3_content2 = "the" story3_content3 = ". I have a problem. It’s almost" story3_content4 = ", so hunters are hunting, butchers are butchering, and people are eating" story3_content5 = "! I need a place to hide. Here’s a" story3_content6 = "to hide in. Shhhhhhhhhhh! Don’t talk, someone is coming. Soon a little" story3_content7 = " walked past Ted and said, “Do you need a place to hide?” But Ted did not understand him, so Ted ran as fast as he could and survived" if story_choice == 1 : print('Story 1: '); print(story1_title.title()); print('Name'); story1_name = input(); print('Age'); story1_age = input(); print('Which holiday'); story1_holiday = input(); print('Favorite'); story1_favorite = input() print("") print(story1_content_1, story1_name, story1_content_2, story1_age, story1_content_3, story1_holiday, story1_content_4, story1_favorite, story1_content_5) elif story_choice == 2 : print('Story 2: '); print(story2_title.title()); print('Name') story2_name = input() print('State Name') story2_state = input() print('Number') story2_number = input() print('Adjective') story2_adjective = input() print('Season') story2_season = input() print('Date') story2_date = input() print('Time') story2_time = input() print('Letter') story2_letter = input() print('Noun') story2_noun2 = input() print("") print(story2_content_1, story2_name, story2_content_2, story2_state, story2_content_3, story2_number, story2_content_4, story2_adjective, story2_content_5, story2_season, story2_content_6, story2_date, story2_content_7, story2_time, story2_content_8, story2_letter, story2_content_9, story2_noun2) else : print('Story 3: '); print(story3_title.title()); print('Name') story3_name = input() print('Animal') story3_animal = input() print('Holiday') story3_holiday = input() print('Animal') story3_animal2 = input() print('Object') story3_object = input() print('Noun') story3_noun = input() print('Verb') story3_verb = input() print('Holiday') story3_holiday2 = input() print("") print(story3_content, story3_name, story3_content2, story3_animal, story3_content3, story3_holiday, story3_content4, story3_animal2, story3_content5, story3_object, story3_content6, story3_noun, story3_content7, story3_verb,story3_holiday2)
Solutions:
Here is an example of one story templet
madlib = input("Would you like to use template 1, 2, 3\n") if madlib == "1": color = input('Enter color: ') adj1 = input('Enter adjective ending with -est: ') adj2 = input('Enter adjective: ') bodypart1 = input('Enter body part (plural): ') bodypart2 = input('Enter body part: ') noun = input('Enter noun: ') animal = input('Enter animal (plural): ') adj3 = input('Enter adjective: ') adj4 = input('Enter adjective: ') adj5 = input('Enter adjective: ') print(f"The {color} dragon is the {adj1} dragon of all. It has {adj2} {bodypart1}, and a {bodypart2} shaped like a {noun}. It loves to eat {animal}, although it will feast on nearly anything. It is {adj3} and {adj4}. You must be {adj5} around it, or you may end up as it`s meal!")