# 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("11_what_we_do_in_the_shadows", "week_7", "lecturenotgraded", assignment_points = 20.0, assignment_tag = 'week7-lecturenotgraded')
# Initialize Otter
import otter
grader = otter.Notebook("11_what_we_do_in_the_shadows.ipynb")
๐ป๐ฆ What We Code in the Shadows ๐๐ป#
The Vampire Council (yes, the same one from What We Do in the Shadows ๐ฆ) has grown tired of inefficient blood-tracking methodsโsticky notes on coffins and carved messages into castle walls just donโt cut it anymore.
They need a modern Python-based blood registry to track the different vampire species in their coven and determine when itโs safe to go outside. You, a newly turned vampire (congrats? ๐ฌ), have been given the task of coding it.
๐ฏ Your Mission (If You Choose to Accept Itโฆ You Donโt Really Have a Choice)#
Implement a class hierarchy that properly represents different vampire types while enforcing ancient vampire laws using:
๐ฆด Abstract Classes (Because Some Things Should Never Be Instantiated)
๐งช Static Methods (Because We Donโt Do Unnecessary Object Creation)
๐ง Multiple Inheritance (Because Real Vampires Have Layers)
๐ Coding Rules of the Vampire Council#
Create an abstract class
Vampire
๐ฆ with:
An abstract method
feed()
, which MUST be implemented by all subclasses.A class attribute
coven
(a list) to keep track of all vampires.A constructor that takes
name
and adds the vampire tocoven
.
Create a mixin
NightCreature
๐ with:
A static method
is_night(time: int) -> bool
that returnsTrue
if itโs nighttime (18-6), otherwiseFalse
. (Because burning alive is a huge inconvenience.)
Create three vampire subclasses ๐ง:
Nosferatu
๐ฆด: Creepy, silent, and way too old. Implementsfeed()
and prints"Nosferatu {name} lurks in the basement and drinks ancient blood ๐ฉธ."
FancyVampire
๐ท: Think Laszlo and Nadjaโelegant, dramatic, and refusing to eat peasant blood. Implementsfeed()
and prints"Fancy Vampire {name} swirls a glass of Type O- ๐ท and complains about peasant blood."
EnergyVampire
๐: Like Colin Robinson, these vampires donโt drink bloodโthey drain life by boring people. Implementsfeed()
and prints"Energy Vampire {name} starts a 2-hour lecture on tax law ๐ and drains the room."
All vampires should inherit from
Vampire
andNightCreature
.
Test the system โ :
Create three vampires (
Nosferatu("Petyr")
,FancyVampire("Laszlo")
,EnergyVampire("Colin Robinson")
).Call
.feed()
on each.Check if
is_night(20)
andis_night(10)
return the correct results.Print the entire coven list.
๐ Expected Output#
Nosferatu Petyr lurks in the basement and drinks ancient blood ๐ฉธ.
Fancy Vampire Laszlo swirls a glass of Type O- ๐ท and complains about peasant blood.
Energy Vampire Colin Robinson starts a 2-hour lecture on tax law ๐ and drains the room.
True
False
['Petyr', 'Laszlo', 'Colin Robinson']
# Import from the abc module ABC and abstractmethod
...
# ๐ฆ Abstract base class for all vampires
# build the Vampire class as an abstract base class with an abstract method feed
...
# define a class variable coven as an empty list
...
# define an __init__ method that takes a name parameter
# and sets the name attribute to the value of the name parameter
# and appends the name to the coven list
...
# define an abstract method feed
...
# ๐ Mixin class to determine if it's night
# build the NightCreature class with a static method is_night that takes a time parameter
# and returns True if the time is between 18 and 06 (nighttime)
...
# ๐ฆด Nosferatu: Creepy, terrifying, and socially awkward
# build the Nosferatu class that inherits from Vampire and NightCreature
# make the Nosferatu class feed method print a message: "Nosferatu {name} lurks in the basement and drinks ancient blood ๐ฉธ."
...
# ๐ท Fancy Vampire: Lives for drama and expensive blood
# build the FancyVampire class that inherits from Vampire and NightCreature
# make the FancyVampire class feed method print a message: "Fancy Vampire {name} swirls a glass of Type O- ๐ท and complains about peasant blood.""
...
# ๐ Energy Vampire: The real horror
# Build the EnergyVampire class that inherits from Vampire and NightCreature
# make the EnergyVampire class feed method print a message: "Energy Vampire {name} starts a 2-hour lecture on tax law ๐ and drains the room."
...
# โ
Test cases
petyr = Nosferatu("Petyr")
laszlo = FancyVampire("Laszlo")
colin = EnergyVampire("Colin Robinson")
# Vampires feeding
petyr.feed()
laszlo.feed()
colin.feed()
# Checking night-time status
print(NightCreature.is_night(20)) # True ๐
print(NightCreature.is_night(10)) # False โ๏ธ
# Checking the coven
print(Vampire.coven) # ['Petyr', 'Laszlo', 'Colin Robinson']
grader.check("what-we-do-in the-shadows")
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("week7-lecturenotgraded", "11_what_we_do_in_the_shadows")