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)
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.
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!".
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.
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.