In any learning environment, it is inevitable that some individuals will progress faster than others. This can make differentiating tasks for your learners a real challenge.
Up until now, you have been learning about the Python language by following fairly didactic instructions, either in written or video form. Afterwards, you’ve hopefully been experimenting with your code to see what else you can do. However, educators often don’t have the time or resources to go through such a process with their students, so what you actually want is more independent learning opportunities in your educational setting.
The following activity is structured in such a way that both beginners and confident Python programmers can develop their skills further.
What are we making?
In this activity, you’re going to create a quiz app. Below is a demonstration of how your application will work.
Here is a link to download the full code for the demonstrated application.
- Don’t start by reading the code. Instead just load and run it in IDLE to have a play with the program.
Once you are happy with how it works, you can dive into the code itself.
- Your first task is to read through the code and add comments to explain as many lines of code as you can. Comments always start with one or more
#symbols. I prefer to use two (
##), but it’s up to you.
For example, you might comment the first few lines like this:
## Import some guizero code from guizero import App, TextBox, PushButton, Picture, Text ## Import code for making random numbers from random import randrange ## Create a list of silly questions. questions = ['What is you name?', 'What is your quest?', 'What is the air speed velocity of an unladen swallow']
If you don’t know what a line of code does, don’t worry: you can leave the line uncommented and come back to it later.
Here’s a link to the code with some comments that we have written to explain the different sections.
You’ve probably already written some comments yourself, so well done! Our comments are there to help you — have a read through them in IDLE to make sure you fully understand what’s happening in the script.
If you’re unsure about anything, now would be a good time to add your questions to the comments below. If you need a little help, or want some clarification on a few lines, don’t be afraid to ask.
Extending the code
Now it’s your turn to alter the code and make it your own. Below are a few suggestions for things you could try. They’re not in any order, so just pick one that looks interesting to you and have a go.
Don’t feel you need to attempt all of the tasks. Do as many or as few as you want. Every little bit of progress you make is a success, so if you’re using Python for the first time in this course and you’ve made it this far, you’ve already achieved a huge amount.
Don’t forget there is guidance for using
guizero here, and that it’s always a good idea to search for answers to a programming question on the internet if you’ve spent a fair amount of time struggling to find a solution.
- Add a few more questions and answers to the quiz.
- Change the application’s background colour.
- Make it so questions are asked in a specific sequence rather than in random order.
- Add in a
ButtonGroupto create a multiple choice quiz.
- Add a picture round, so that an image is displayed with a question.
- Give the user a choice of being asked the questions in a different language.
- Alter the code so that upper and lower case is accepted.
- Hide the ‘Next’ button until the user has submitted an answer.
- Store and display a score of the number of correctly answered questions.
- Load a set of questions and answers from a text file, so that the user can choose different topics.
If you have other ideas, feel free to have a go at programming them, and please share your ideas and finished scripts in the comments section.