# 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("1_kanye_q", "week_5", "practicequiz", assignment_points = 16.0, assignment_tag = 'week5-practicequiz')

# Initialize Otter
import otter
grader = otter.Notebook("1_kanye_q.ipynb")

โ“ Practice Quiz: Kanye Says the Darndest Things! ๐Ÿค”#

Kanye is known for making outrageous, unpredictable statements. Your job?

Write functions that track, analyze, and fact-check Kanyeโ€™s wildest quotes! ๐ŸŽค๐Ÿ”ฅ

# Run this block of code by pressing Shift + Enter to display the question
from questions._1_kanye_q import Question1
Question1().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._1_kanye_q import Question2
Question2().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._1_kanye_q import Question3
Question3().show()

Question 1 (Points: 7.0): Kanyeโ€™s Wildest Quotes Tracker ๐ŸŽค๐Ÿ”ฅ#

Kanyeโ€™s interviews are full of unpredictable statements. We need a function to track what he says and detect the wildest moments.

The program should:

  1. Accept an arbitrary number of Kanye quotes using *args.

  2. Detect if any quote exceeds 500 characters, and print a warning if detected.

  3. Calculate the total length of all Kanyeโ€™s statements and return it.

  4. Allow an optional alert_threshold parameter using **kwargs to adjust the warning limit dynamically.

Implementation Details#

  1. Define a function track_kanye(*args, **kwargs).

  2. Loop through all *args values and:

    • Print a warning message if any quote exceeds 500 characters or the provided alert_threshold from **kwargs.

  3. Calculate the total length of all quotes.

  4. Return the total character count.

# Define the function to monitor Kanye quotes
...

    # Extract the alert threshold from the keyword arguments
    # Recall kwargs is a dictionary, and thus we can use the get method to extract the value of the key "alert_threshold"
    ...
    
    # Initialize an empty list to store warnings
    ...
    
    # Iterate over the quotes and check if any quote exceeds the alert threshold
    # If a quote exceeds the alert threshold, append a warning to the warnings list
    # we have provided a sample warning message for you to use, look at the call to determine the correct variable to use
    ...
            warnings.append(f"โš ๏ธ Warning: Extremely long Kanye quote detected ({len(quote)} characters)!")

    # Calculate the total length of all quotes
    # We can use a generator expression to calculate the total length of all quotes
    # Store the total length in a variable called total_length
    ...
    
    # Return the total length of all quotes and the warnings
    ...
grader.check("Kanye-Quote-Analysis")

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("week5-practicequiz", "1_kanye_q")