# 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 ๐Ÿ“”๐Ÿ’”#

diary

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#

diary

Instructions:#

Youโ€™re reading through your old diary to find entries containing the word โ€œawkward.โ€ Write a Python program to:

  1. Loop through a list of diary entries.

  2. If โ€œawkwardโ€ is found, print the entry.

  3. 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 the diary_entries list, save the current entry in a temporary variable entry.

  • 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 the entry. 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.

  1. 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")