Featured resource
Tech Upskilling Playbook 2025
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Learn more
  • Labs icon Lab
  • Cloud
Google Cloud Platform icon
Labs

Building Class Hierarchies with Inheritance in Python

Inheritance commonly gets a bad reputation and is fairly easy to misuse, but when building a system that requires multiple variations of the same general concept, then it is the right tool for the job. Knowing when and how to use inheritance is important for being the most productive object-oriented programmer that you can be. In this hands-on lab, you'll be building the class hierarchy for question types used in a quiz system. By completing this lab, you'll have demonstrated that you know how to factor class logic across a tree of classes to minimize repeated code and leverage how inheritance allows you to share logic.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Advanced
Duration
Clock icon 1h 15m
Last updated
Clock icon Sep 01, 2025

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Implement the Base Question Class

    The base Question class is the class for multiple-choice, single answer questions. For this class to meet the business requirements, it will need to have the proper initialization, a select method, a grade method, and a customized __str__ method. The string output should work by printing the following:

    [QUESTION_TEXT]
    
    1. [OPTION]
    2. [OPTION]
    3. [OPTION]
    4. [OPTION]
    
  2. Challenge

    Create the TrueFalseQuestion Class by Subclassing Question

    When looking at the TrueFalseQuestion class, we want to simplify the initialization since the options are obvious, and we'd also like to customize the printed representation so that it starts with True/False:, unless the question text provided already begins with the words "True" or "False" (ignoring case). Here's what the output would look like:

    True/False: [QUESTION_TEXT]
    
    1. [True or False (randomized order)]
    2. [Opposite of option 1.]
    
  3. Challenge

    Create the MultipleSelectQuestion Class by Subclassing Question

    The biggest difference between a multiple-choice, multiple correct answer question type and the standard multiple choice question type is that the correct_choice and selected_answer attributes need to work with a list of strings instead of a single string. Changing how those two things operate will potentially require adjusting how select and grade work.

    Additionally, the number of correct answers should be included in the printed output for a MultipleSelectQuestion. Here's an example with three correct answers:

    [QUESTION_TEXT] (select 3)
    
    1. [OPTION]
    2. [OPTION]
    3. [OPTION]
    4. [OPTION]
    5. [OPTION]
    

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.