Code Club
Mr Fox runs a coding club after school in which the group learn and explore the programming language Python. Using Python, we can build chatbots, games, password checkers and really anything that runs on a computer.
"I love code club. It has made me so much faster at typing and has made me understand things I would have never been able to before I joined!"
- April (Year 6)
"Code Club is my favourite club because you get to make cool things"
- Philly (Year 4)
RGB Numbers and Iteration
Matheus is achieving a number of interesting things with this program! Notice how on line 6, he has not written the colour name, instead he has provided three integers. This is called an RGB number and is a very common way of identifying colours in programming - we will be using these in our upcoming International Space Station project. Each value represents either Red, Green or Blue to a maximum of 255. By mixing the digits, you can create any colour you like.
Matheus has also used variables within his loop to grow the pattern. Outside the repeated pattern, he has saved 0 inside a space called 'count' (line 8). Within the loop (everything under 'while True:'), he adds one to 'count' every time the code repeats (line 11). As you can see in the values printed at the bottom, this is happening very quickly. He has then said his code-controllable turtle, Bob, only moves forward however many steps are saved in 'count'. Therefore, because 'count' continues to grow, Bob moves slightly further with each iteration.
Click the play button and see what happens!
Infinitely Looping Turtles
Here, Oscar has brilliantly used a forever loop ("while True:") to make his digital turtle do the following three instructions over and over again:
1. Make a circle
2. Move forward
3. Turn left
In programming, there are two types of loop: those that go forever (forever/infinite) and those that repeat only a set amount (count-controlled). For an pattern such as this, Oscar has gone for a loop that keeps going!
Looping like this is one of the many reasons we use computers to help us with daily tasks. Machines can be asked to do repetitive actions extremely quickly.
Click the play button and see what happens!
April's Interactive Story
Logan's Password Checker
Art with Turtles
Here we are exploring one of modern programming fundamental forms: object orientation. First, we imported the module 'turtle' to bring in to our program a collection of pre-programmed functions/methods/commands. One of these allows us to make 'objects' that are imbued with all the imported controls. In line 3, this student does this by declaring a variable 'john' and using the class 'Turtle()' to bind the controls. Now, 'john' can be manipulated with further lines of code. We can define john's shape with john.shape() or its colour with john.color(). We can then control movement with john.forward() and john.left() with the turtle leaving behind a pen-like trail. On line 8, this student has set the turtle controls inside a count-controlled loop that runs 10,000,000 times. Because the turning angles are irregular, over many iterations, the turtles can create beautiful geometric patterns.
Astro Pi Certificates
The Code Clubbers received their Astro Pi certificates today, confirming that their code ran on the International Space Station! On the back, you can see where the ISS was when it ran each individual's code.
Password checker
This code works by saving the correct username and password inside variables (username and password). We then use the input() function to ask our user to type in what they think the username and passwords are - they are also saved in variables (typedUsername and typedPassword).
We then use conditional selection to test whether the correct usernames and passwords are the same as the typed usernames and passwords. What the line starting with 'if' is really saying is 'if username is the same as typedUsername and password is the same as typedPassword, then print out "Login Successful", otherwise (else), print our "Incorrect!".
Interactive Story
Similar principles have been applied to this interactive story. By saving a number inside the variable 'decision1', this student allows the user to make a decision to branch the story. Again, conditional selection is used to test the variable. If a '1' is saved inside 'decision1', the first message will print, ending the game with the function quit(). Only by choosing '2' will the story move on to its next phase. In line 1, this student has imported the function sleep() from the module time. This allows the code to pause as it is run, allowing the user to follow the flow of the story more easily.
Astro Pi
Wicklewood Code Clubbers have been writing code to run on the International Space Station! An Astro Pi is a small computer than can read Python and execute functions as a result. By submitting code through Rasberry Pi's portal, the children allow their code to be sent to space. This year, the Astro Pi is displaying images to entertain the astronauts. The added twist is the use of the sense() function. Children programmed the Astro Pi's camera to take a colour reading from the environment and save it in a variable. The displayed image can then change depending on what the camera can see. If someone approaches the machine with a red t-shirt on, elements of the image will copy the colour.
Guess the Number
We wrote a 'Guess the Number' game to consolidate some of the key coding concepts. We used the random() function to save a random number into a variable, simulating a choice made by the computer. We then used the input() function to take a number from the user of our program. We used conditional selection to compare the two variables - if they contained the same thing, the player won. We set everything within a 'while loop' (infinite looping/repetition within Python). In order for the code to repeat, 'gameOn' must be True (as declared at the top). Once the game is won, 'gameOn' is changed to False, thereby ending the loop and stopping the game. If the player guesses incorrectly the loop continues, and they have another chance.
Before writing this program, Code Club independently made a list of what needed to be built. This is a crucial programming skill called decomposition.