# You must make sure to run all cells in sequence using shift + enter or you might encounter errors
from pykubegrader.initialize import initialize_assignment
responses = initialize_assignment("8_mortified_loops_q", "week_4", "readings", assignment_points = 21.0, assignment_tag = 'week4-readings')
# Initialize Otter
import otter
grader = otter.Notebook("8_mortified_loops_q.ipynb")
โ ๐ Mortified: High School Diaries ๐๐#
Relive the cringe-worthy moments from your high school diary while mastering Python loops and statements!
# Run this block of code by pressing Shift + Enter to display the question
from questions._8_mortified_loops_q import Question1
Question1().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._8_mortified_loops_q import Question2
Question2().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._8_mortified_loops_q import Question3
Question3().show()
Diary Keyword Check#
Instructions:#
Youโre reading through your old diary to find entries containing the word โawkward.โ Write a Python program to:
Loop through a list of diary entries.
If โawkwardโ is found, print the entry.
Stop reading if you encounter โSTOPโ in any entry.
Specific Instructions:#
Use the
diary_entries
list provided.Use the function diary_search provided.
create a
for
loop to iterate through thediary_entries
list, save the current entry in a temporary variableentry
.Check if the word โSTOPโ is in the
entry
. If it is, print โProcessing stopped.โ and break the loop.Check if the word โawkwardโ is in the
entry
. If it is, print โAwkward entry: โ followed by theentry
. Use an f-string to format the output.
Use a for
loop, break
, and continue
statements to implement this.
Example Entries:#
diary_entries = [
"Math class was so awkward today.",
"Went to the mall and saw my crush.",
"STOP this madness.",
"Had pizza for dinner."
]
Output should be:
Awkward entry: Math class was so awkward today.
Processing stopped.
diary_entries = [
"Math class was so awkward today.",
"Went to the mall and saw my crush.",
"STOP this madness.",
"Had pizza for dinner.",
]
def diary_search(diary_entries):
...
grader.check("Mortified-DiaryKeywordCheck")
Counting the Words in Your Diary Entries#
Instructions:#
Write a Python program to count the total number of words across all diary entries. Use a for
loop to process each entry and the .split()
method to count words in the entry.
Initialize a variable
total_words
to 0.
Example Entries:#
diary_entries = [
"I had a good day today.",
"So awkwardโmy crush noticed my new haircut!",
"Nothing special happened."
]
The program should output:
Total words: 18
Mortified Podcast Story: The Kissing Catastrophe
It all started with the Great Kissing Pact of ninth grade. My best friend Tara and I, armed with an unlimited supply of naivety and Dr. Pepper, decided that this year would be the year. We had been marinating in teen rom-coms for months, and the message was clear: ninth grade was supposed to be magical. First dances. First kisses. First time realizing boys donโt look like Zac Efron.
But the problem? Neither of us had ever kissed anyone. And we werenโt exactly thriving in the social scene. I was in marching band, and Tara was in something called the Book Bowl Club (which, for the record, is not as cool as it sounds). So, we made a deal. By the end of the school year, we would each experience The Kissโข.
For Tara, things unfolded pretty smoothly. She โfell in loveโ with a kid named Brad who wore Axe body spray like a force field. By Valentineโs Day, they were sharing awkward hand-holds and secret smiles during study hall. I heard from a reliable source (Tara herself) that Brad kissed her behind the bleachers after a basketball game. She was officially on the scoreboard.
And then there was me. By May, I had kissed exactly zero people. My options wereโฆ limited. There was Kevin, who thought deodorant was optional, and Derek, who only communicated through anime references. But thenโlike some cursed miracleโthere was Jason.
Jason wasnโt cool, exactly, but he was what we called a โfloater.โ He could talk to anyone. He wasnโt in band, but he sat at our lunch table because he thought Taraโs stories about her cat were funny. One Friday, as we were walking home from school, Jason casually asked if I wanted to hang out at the park.
My heart exploded. I had never been โasked out,โ not even indirectly. Tara was thrilled for me. She braided my hair, lent me her sparkly lip gloss, and whispered, โTonightโs the night.โ And somehow, I believed her.
At the park, we swung on the swings and talked about important ninth-grade things: movies, homework, and whether we thought aliens existed. Then, as the sun started to set, Jason turned to me and said, โYouโre really cool, you know that?โ
I froze. Was this it? Was this the moment?
Jason leaned closer. My brain went into full panic mode. What if I did it wrong? What if my lips were weird? And most horrifying of all: what if I missed? But before I could think it through, I leaned in tooโonly way too fast. My face collided with Jasonโs in what can only be described as a headbutt.
โOh my god, are you okay?โ he asked, rubbing his nose.
I wanted the Earth to swallow me whole. โIโm fine!โ I squeaked, clutching my forehead like it was bleeding.
Jason laughedโthankfullyโand said, โMaybe we should try again.โ
Reader, we did not. I mumbled something about needing to get home and practically sprinted back to my house. Tara was waiting on my porch, hopeful and smiling.
โWell?โ she asked.
โI think I gave Jason a concussion.โ
Mortified Takeaway: First kisses are messy. Sometimes theyโre magical, sometimes theyโre a headbutt. But either way, they make for a story youโll laugh about one dayโif youโre lucky.
diary_entries = [
"""**Mortified Podcast Story: The Kissing Catastrophe**
---
It all started with the Great Kissing Pact of ninth grade. My best friend Tara and I, armed with an unlimited supply of naivety and Dr. Pepper, decided that **this year would be the year**. We had been marinating in teen rom-coms for months, and the message was clear: ninth grade was supposed to be magical. First dances. First kisses. First time realizing boys donโt look like Zac Efron.
But the problem? Neither of us had ever kissed anyone. And we werenโt exactly *thriving* in the social scene. I was in marching band, and Tara was in something called the **Book Bowl Club** (which, for the record, is not as cool as it sounds). So, we made a deal. By the end of the school year, we would each experience The Kissโข.
For Tara, things unfolded pretty smoothly. She โfell in loveโ with a kid named Brad who wore Axe body spray like a force field. By Valentineโs Day, they were sharing awkward hand-holds and secret smiles during study hall. I heard from a reliable source (Tara herself) that Brad kissed her behind the bleachers after a basketball game. She was officially on the scoreboard.
And then there was me. By May, I had kissed exactly zero people. My options wereโฆ limited. There was Kevin, who thought deodorant was optional, and Derek, who only communicated through anime references. But thenโlike some cursed miracleโthere was Jason.
Jason wasnโt *cool*, exactly, but he was what we called a โfloater.โ He could talk to anyone. He wasnโt in band, but he sat at our lunch table because he thought Taraโs stories about her cat were funny. One Friday, as we were walking home from school, Jason casually asked if I wanted to hang out at the park.
My heart exploded. I had never been โasked out,โ not even indirectly. Tara was thrilled for me. She braided my hair, lent me her sparkly lip gloss, and whispered, โTonightโs the night.โ And somehow, I believed her.
At the park, we swung on the swings and talked about **important ninth-grade things**: movies, homework, and whether we thought aliens existed. Then, as the sun started to set, Jason turned to me and said, โYouโre really cool, you know that?โ
I froze. Was this it? Was this the moment?
Jason leaned closer. My brain went into full panic mode. What if I did it wrong? What if my lips were *weird*? And most horrifying of all: what if I missed? But before I could think it through, I leaned in tooโonly way too fast. My face collided with Jasonโs in what can only be described as a headbutt.
โOh my god, are you okay?โ he asked, rubbing his nose.
I wanted the Earth to swallow me whole. โIโm fine!โ I squeaked, clutching my forehead like it was bleeding.
Jason laughedโthankfullyโand said, โMaybe we should try again.โ
Reader, we did not. I mumbled something about needing to get home and practically sprinted back to my house. Tara was waiting on my porch, hopeful and smiling.
โWell?โ she asked.
โI think I gave Jason a concussion.โ
---
**Mortified Takeaway**: First kisses are messy. Sometimes theyโre magical, sometimes theyโre a headbutt. But either way, they make for a story youโll laugh about one dayโif youโre lucky."""
]
def diary_word_count(diary_entries):
# Initialize a variable to store the total word count
...
# Iterate over each entry in the diary_entries list
# count the number of words in each entry and add it to the total word count
...
# Print the total word count using the f-string
# Your output should look like this: "Total words: 123"
...
diary_word_count(diary_entries)
grader.check("Mortified-DiaryWordCount")
Submitting Assignment#
Please run the following block of code using shift + enter
to submit your assignment, you should see your score.
from pykubegrader.submit.submit_assignment import submit_assignment
submit_assignment("week4-readings", "8_mortified_loops_q")