# 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("10_inheritance_q", "week_7", "readings", assignment_points = 24.0, assignment_tag = 'week7-readings')

# Initialize Otter
import otter
grader = otter.Notebook("10_inheritance_q.ipynb")

๐Ÿˆ Inheritance in Python: Building NFL Madden Player Classes#

The Madden NFL video game franchise has been a staple for football fans for decades. Each player in the game has unique attributes and abilities, but all players share common characteristics like name, position, and rating.

In Python, inheritance allows us to model this by creating a base Player class and extending it into specialized player types like Quarterbacks, Wide Receivers, and Defensive Linemen.

Letโ€™s explore how inheritance helps us organize player attributes and skills in Madden NFL using Python classes!

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

Question 1 (Points: 15.0): ๐Ÿˆ Free Response: Create an Inheritance Structure for Madden NFL Players#

Implement a class hierarchy for Madden NFL players:

  • Create a base class Player with:

    • name (str) and rating (int).

    • A method describe() that prints player details. It should print Player: <name>, Rating: <rating>, where the <name> and <rating> are the playerโ€™s attributes.

  • Create a subclass Quarterback that:

    • Inherits from Player.

    • Adds a throwing_power attribute.

    • Overrides describe() to include throwing_power. To do this, you need to call super on the describe() method of the parent class.

Example Usage#

qb = Quarterback("Lamar Jackson", 91, 96)
qb.describe()

Expected Output:

Player: Lamar Jackson, Rating: 91
Throwing Power: 96
...

# Example usage
qb = Quarterback("Lamar Jackson", 91, 96)
qb.describe()
grader.check("Madden-Inheritance-Classes")

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-readings", "10_inheritance_q")