PyQuiz is an interactive Python coding practice tool designed to help students learn and practice Python programming through a series of coding questions. It provides a user-friendly interface using IPython widgets, making it ideal for use in Jupyter notebooks or similar interactive Python environments.
- Interactive coding questions with real-time feedback
- Support for multiple question types and input formats
- Customizable questions loaded from JSON files
- Hint system for additional guidance
- Progress tracking
- Test case execution and result display
- Program output capture and display
-
Ensure you have Python 3.x installed on your system.
-
Install the required dependencies:
pip install ipywidgets pandas numpy -
Download the
pyquiz.pyfile from the GitHub repository:wget https://github.com/brendanpshea/computing_concepts_python/raw/main/python_code_quiz/pyquiz.py
-
In your Jupyter notebook or interactive Python environment, import the
PracticeToolclass:from pyquiz import PracticeTool
-
Create an instance of the
PracticeToolclass, specifying the path to your JSON file containing the questions:practice_tool = PracticeTool(json_url='path_to_your_questions.json')
You can also use a URL to load questions from a remote source:
practice_tool = PracticeTool(json_url='https://example.com/questions.json')
-
The tool will automatically display and allow interaction with the coding questions.
To create your own set of questions, prepare a JSON file in the following format:
{
"questions": [
{
"function_name": "example_function",
"parameters": ["param1", "param2"],
"description": "Write a function that does X",
"input_type": ["int", "string"],
"answer_code": "def example_function(param1, param2):\n # Correct implementation here\n return result",
"hint": "Consider using method Y",
"test_inputs": [[1, "a"], [2, "b"]]
},
// Add more questions here
]
}function_name: The name of the function to be implementedparameters: List of parameter names for the functiondescription: A description of what the function should doinput_type: Types of inputs for each parameter (can be a single string for all parameters)answer_code: The correct implementation of the functionhint(optional): A hint to help students if they get stucktest_inputs(optional): Custom test inputs for the function
- Questions are presented one at a time with a clear description and function signature.
- Sample runs are displayed to help students understand the expected behavior.
- Students can write their code in a text area with syntax highlighting.
- The initial function signature is provided automatically.
- Students can run their code against predefined test cases.
- Test results are displayed in a color-coded table for easy interpretation.
- Each question can have an optional hint that students can reveal if needed.
- A progress bar shows the current question number and total questions.
- Students can skip to specific questions using a dropdown menu.
- Any output produced by the student's code is captured and displayed separately.
Contributions to improve PyQuiz are welcome. Please feel free to submit pull requests or open issues on the GitHub repository.
This project is open source and available under the MIT License.
- Thanks to all contributors and users who help improve this educational tool.