Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

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

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • 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
Lab platform
Lab Info
Level
Advanced
Last updated
Sep 18, 2025
Duration
1h 15m

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]
    
About the author

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.

Real skill practice before real-world application

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.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight