How to create an interactive quiz app with Python?¶
Since the main purpose of the learning guide is to teach you how to create an open source project for an existing app or library, we will only shortly describe quizli
itself.
Learning Objectives
By the end of this section, you should be able to:
- List the main building blocks of the
quizli
- Modify & improve
quizli
via the experience you gained through the assignments - Work with the
rich
library to make your own app interactive and beautiful
1. Main building blocks of a simple quiz app¶
Assignment 1
- a) Read through the code reference of the
quiz
module - b) Take a look at the exemplary jupyter notebook about creating a simple quiz
Resources
- Dataclasses: PEP-557 & Section in Python Docs
2. Make your quiz beautiful and interactive¶
In order to bring color and interactivity into our quiz we make heavy use of the rich
library.
Assignment 2
- a) Read through the code reference of the
layout
module and thesession
module - b) Create your own quiz layout class that inherits from
QuizLayoutBase
, similar to theFancyQuizLayout
. It could be a minimalist quiz layout, or maybe you want to show off your creative power and design a beautiful und super-complex layout.
Resources
- Read through the following sections of the
rich
documentation:
2. Dynamically create a quiz¶
The examples
module shows how to dynamically create a quiz and have it automatically pop up in quizli's CLI.
Assignment 3
- a) Read through the code reference of the
example
module - b) Create your own dynamic quiz, by implementing a function similar to the
python_quiz
and thebinary_number_quiz
functions. Add your quiz as a variant to theQuizKind
enumeration, so that it will be automatically added as an option in quizli's CLI. - c) The built-in Python quiz has a problem: when asking for the name of a Python object/module given it's description, the description sometimes contains the answer itself. Improve the
python_quiz
by writing code that strips out the answer from the question field before showing it.
Last update:
March 11, 2022