Want to keep learning?

This content is taken from the Raspberry Pi Foundation & National Centre for Computing Education's online course, Scratch to Python: Moving from Block- to Text-based Programming. Join the course to learn more.
A photograph of a young girl programming on her own

Independent learning

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 learners, so they want more independent learning opportunities.

The following independent activity is structured in such a way that both beginners and confident Python programmers can develop their skills further.

In this activity, you are going to look at a GUI I have created, and read and attempt to explain the Python code that I have used. You will then attempt to extend my program. As usual, you can reuse this activity with your own learners.

Below is a demonstration of my GUI:

An animation of a GUI consisting of some text, a text box for answers to be entered, a "Check answer" button, and a "Next" button. Initially the question "Fill in the blank - Pseudo blank" is presented, the answer "code" is entered into the text box and the "Check answer" button is clicked. The question text changes to "correct". When the "Next" button is clicked, the text is replaced by a new question: "What is the Python equivalent to the Scratch "say" block?" The answer "print" is entered into the text box and the "Check answer" button is clicked.The question text changes to "correct". When the "Next" button is clicked, the text is replaced by a new question: "What Python module contains the randit function?" The answer "time" is entered into the text box and the "Check answer" button is clicked. The question text changes to "incorrect". When the "Next" button is clicked, the animation loops.

The code

  1. Here is a link to download the full code for the demonstrated application. Do not read the code, just load and run it to have a play with the program.

  2. 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. In the classroom you can ask your learners to do this at the same time to give them more confidence and understanding of the code.

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 questions
questions = ['Which Python function is equivalent to the Scratch "say" block ?',
             'Which Python module contains the randint function ?',
             'Fill in the blank - pseudo____ ?']

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.

Commented code

Here’s a link to the code with some comments that I have written to explain the different sections.

My comments are there to help you — have a read through them to make sure you fully understand what’s happening in the code. This will also fill any gaps in your comments. You can then use a version that has lots of comments with your learners after they have added their own comments.

If you’re unsure about anything, now would be a good time to add your questions to the comment section 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.

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.

If you use this activity with your learners, you can give one extension task each and then share each other’s code, or differentiate by giving more tasks to the higher-ability learners. You can continue the activity by asking the higher-ability learners who have completed their task to support other learners, and then they can use the other learners ideas and code to complete more tasks on their own program.

Don’t forget that there is guidance for using guizero, 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.

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.

Possible extensions

  1. Add some more questions and answers to the quiz.
  2. Add a picture round, so that an image is displayed with a question.
  3. Alter the code so that upper and lower case answers are accepted.
  4. Hide the ‘Next’ button until the user has submitted an answer.

If you have other ideas, feel free to have a go at programming them. Please share your ideas and finished programs (using a Pastebin link) in the comments section.

Share this article:

This article is from the free online course:

Scratch to Python: Moving from Block- to Text-based Programming

Raspberry Pi Foundation