Paul Sutton

CodeClub

Code Club – Trinket and python Modules

Trinket allows you to use a number of different modules to add functionality to your programs.

Code Club have added a py5 module for their own projects. So this post will examine how to add one of the available libraries to your program.

Firstly a list of the modules that Trinket.io provides can be found here. along with some documentation for each.

So to add a module we need to use the import command.

Start with a blank new Python 3 project and enter the following

#!/usr/bin/env python3 #use python 3

Then the instruction to import the required module.

import numpy

Now test if you don't get errors proceed to add

from numpy import *

And test again.

Should give no errors, in which case you can now start to use module numpy

Other info

You can use modules such as Numpy and matplotlib in software such as Jupyter Notebook

Tags

#Python,#Trinket,#Modules,#HowTo,#CodeClub

New Python worksheets

I am now working on some new Python resources. I uploaded two of the resources mentioned in the previous post, and took some of the code from the TkInter resource (which is still available) and created a resource to look at testing if text from a user is what is being asked for.

As of 22/05/2023, I have :-

  • Python Arrays
  • Python String Length
  • Check User Input
  • Python3 Functions 2
  • Python3 Functions 1
  • Trinket Get Started
  • Python Nested Loops2
  • Python Nested Loops

These are designed to be used along side each other. As we are also using Trinket at Code Club.

My intention is to create more and use them as a Teaching Assistant or Tutor in a school or elsewhere. I am employed by an agency so if you want someone who can help teach computing in a primary school or have a group of children who want to move up then please get in touch. I can send my CV which will have my employer details on.

I can also help with Scratch, Micro:bit, electronics, Science etc

I will NOT be making these resources generally available.

These are already available

Tags

#CodeClub,#Python.#Programming,

Old python worksheets

A few years ago I created some worksheets to help teach nested loops. They are probably for Python2.x but can be adapted.

These are OLD and are therefore provided 'as is'. If you need help please send me a fediverse message on @[email protected]

Tags

#CodeClub,#Python.#Programming,

Code Club – Python functions 2

So to follow the previous post, we are going to look at passing 2 arguments to a function, adding them together, then displaying the result.

Firstly open a new Python Trinket

Firstly we are going to tell the interpreter to use python3.

#!/usr/bin/env python3 #use python 3

Now we create a function to take two arguments and display the sub of both

def add_numbers(x,z):
  #print(x)
  #print(z)
  add = (int(x) + int(z))
  print ('Total = ')
  print(add)

Get user input

x = input("First Number") # ask for first number
z = input("Second Number") # ask for second number

Convert to integers

int(x)
int(z)

Call function and pass values to function

add_numbers(x,z)

Tags

#CodeClub,#Python.#Programming,#Functions,#Arguments

Code Club – Simple Python 3 Functions

As we are learning Python at Code Club, I am going to make some related posts looking at the very basics of this. We are using Trinket.io for this

Firstly open a new Python Trinket

Firstly we are going to tell the interpreter to use python3.

#!/usr/bin/env python3 #use python 3

We are going to create a function called print_name() and then call it. The function will just print hello to the standard output.

def print_name():
  print ("hello")
  
print_name()  

So this in does the same as what

print ("hello")

To the next step is to run the function several times.

We could run

print_name()  
print_name() 
print_name() 

However it is probably better to put the print_name() in a loop, so it calls the function a specified number of times (in this case 4)

for x in range(0,4):
  print_name()

So this will now call the print_name() four times (or however many times is specified.

Assuming this works, we can now add some user interactivity

y = input("iterations")

As we are dealing with numbers (integers) than y will be a string we fix this in the line for x in range(0,int(y)): int(y) will convert string y in to integer y

Final program looks like this:-

def print_name(y):
  print ("hello")

y = input("iterations")
for x in range(0,int(y)):
  print_name(y)

Will ask for user input, store this in the variable y, as an integer. It run a loop which calls the function y times. Which in turn prints hello.

If you add the line

print(y)

After the

print("hello") 

Line, then the program should output a number count for each iteration. This can be a useful too for debugging loops. This will also make use of the fact we are passing the value of y to the function.

Links

Tags

#CodeClub,#Programming,#Education,#Python.#Functions

Code Club 20/5/2023 Write up

Today we carried on with with the Python activities that we started last week. Attendees are mostly undertaking the same path just different activities within that.

Useful Links

If you also sign up to the Raspberry Pi foundation, you can track progress and collect badges. This is optional, as this presents more ways for data to be collected.

This is one of the projects that we built today – Target Practice *

  • NOTE : This video is of the project preview and not the final project, which looks the same.

We also looked at a Raspberry Pi Pico and had a quick look at how Chat GPT can be used to generate code. It did seem however that it produces example code from using the older gpio libraries, rather than the newer GPIO Zero library.

But it did produce the code required, regardless of library being used.

Something to look at next time, so the plan is to experiment more with this. This raspberry Pi also uses Micro Python

There is no Code Club on Saturday 3rd June, so the next event will be the STEM Group on 10th June.

#CodeClub

Code Club – Compute-IT

The next Paignton Library code club is on Saturday 20th May 2023 10 am to 12:00. We can carry on with what we are doing,

You may have noticed a link to compute-it added to the list of websites, if you're not sure what this is I have put a brief description below. Some of the young people attending both code club and stem group have used it

Compute IT consists of puzzles where you need to follow the instructions presented in the code displayed on the screen, This stars out simple and gets more complex or involved as you go.` '

I have added a video to my peertube resources to illustrate.

Useful Links

Tags

#CodeClub,#Scratch,#Coding,#Hacking,#Python,#STEM,#Lua,#Roblox

Code Club 6/5/2023 Write up

We had a lower turnout today, probably due to the coronation. Nevertheless we were actually very productive.

A new member started off with the Free code camp course on scientific computing, which is mostly video with Q&A. This really good, but not very interactive so we moved on to the Code Club Python activities

Using trinket to create a program to simulate rolling a dice

This worked much better, so we they are going to carry on at home, them come back next week to the STEM group.

Useful Links

Beginner Level

Next event

13th March – STEM Group 11 – 15:00 20th March – Code Club 10 – 12:00

New people welcome, as a group we can all learn together and support each other.

It would recommend getting accounts with the following, and bringing the details with you. A parent / guardian may need their phone to help facilitate logins.

Tags

#CodeClub,#Scratch,#Coding,#Hacking,#Python,#Trinket,

Code Club 6/5/2023 reminder

The next Paignton Library code club is on Saturday 6th May 2023 10 am to 12:00. We can carry on with what we are doing,

Useful Links

Beginner Level

Roblox

As Roblox is very popular and allows you to develop within the game the following may be useful.

Note you need your own laptop with this installed so you can develop Lua projects for Robox. You can use Replit to learn Lua but need an account.

GNU / Linux BASH

This is something that once mastered can be very beneficial

Python

Web Site Creation

Other

Free Code Camp offer a wide range of follow along interactive courses, tutorials etc. You will need an account but it is probably worth getting on.

Older Links

I have previously included links to other resources, as I have now updated this page then the old links are still on the previous post.

Tags

#CodeClub,#Scratch,#Coding,#Hacking,#Python,#STEM,#Lua,#Roblox

Paignton Library Code Club – Minetest

Some of the laptops at Code Club have had Minetest installed, this is the free software clone of Minecraft. As with Minecraft, Minetest has lots of mods etc available.

The diode.zone peertube instance has some reviews of these mods. Please see link below.

Links

Tags

#CodeClub,#Minetest,#Mods