# 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:
Accept an arbitrary number of Kanye quotes using
*args
.Detect if any quote exceeds 500 characters, and print a warning if detected.
Calculate the total length of all Kanyeโs statements and return it.
Allow an optional
alert_threshold
parameter using**kwargs
to adjust the warning limit dynamically.
Implementation Details#
Define a function
track_kanye(*args, **kwargs)
.Loop through all
*args
values and:Print a warning message if any quote exceeds
500 characters
or the providedalert_threshold
from**kwargs
.
Calculate the total length of all quotes.
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")