Paul Sutton

trinket

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


MastodonPeertubeQoto sign up

Donate using Liberapay

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,


MastodonPeertubeQoto sign up

Donate using Liberapay

More Trinket Coding

Trinket is a web based development platform. One of it's features is the programming language blocks, which is in fact a block based front end and creates Python programs.

I am sharing these on my blog today, even though I also shared earlier in the week on LinkedIn and also on Twitteras part of the Paignton Library Virtual Code Club.

Drawing a circle

circle1

And the associated output

circle1

Drawing a star

star1

And the associated output

star2

I am working on a book to update my previous Nested loops guide I wrote a few years ago. This needed updating anyway so it would cover Scratch 3.0. This book / guide is work in progress, and will be typeset in $\LaTeX$ using Overleaf

#programming, #trinket, #Blocks, #python, #WebIDE, #LaTeX, #Overleaf, #nestedloops, #loops, #codeclub

cc-by logo

Licenced under Attribution 4.0 International (CC BY 4.0)


MastodonPeertubeQoto sign up

Donate using Liberapay

At Paignton virtual Code Club, we are now approaching the end of the Scratch modules. Well done to everyone. The next step is probably to progress to Python [2][3].

If you don't feel ready to do lots of typing, you may want to look at Trinket and blocks. Then perhaps move to the Code Club modules [3].

Blocks, as the name suggests, is a block based system. The difference here is, that the blocks are all Python statements and code. So combining these allow you to easily start coding in Python.

To get started you need to sign up for an account on the Trinket website [1]

trinket

Click you user name and select new trinket and then select blocks

select blocks

You are now presented with your development area.

dev area

You may want to change your project title to something meaningful.

change title

You can select the category of block, then simply use click / drag in similar way as you would with Scratch.

So in this example I am just going to draw a square.

draw square

As we are using turtle, you will need to change the pen up, block so that it says pen down.

change command

Adding comments to your code is important, as it helps you keep track of what the code is doing and helps with debugging also helps others understand your code.

add comment

You can also view the Python code that is produced, this can be copy / pasted to IDE so you can just run the Python code on its own.

![View Python]

https://raw.githubusercontent.com/zleap/blogmedia/master/trinket/square-python-code.png

Finally you can share your project with others.

share

Hopefully this is helpful.

Resources

1 Trinket 2 Python 3 Code Club python Modules

#codeclub,#paignton,#trinket,#python,#coding,#skills,#technology

cc-by logo

Licenced under Attribution 4.0 International (CC BY 4.0)


MastodonPeertubeQoto sign up

Donate using Liberapay