Learn TRINKET-PYTHON with Real Code Examples
Updated Nov 26, 2025
Code Sample Descriptions
1
Hello World in Trinket (Python)
print("Hello World")
A simple Trinket Python program that prints 'Hello World'.
2
Hello World with Turtle in Trinket (Python)
import turtle
pen = turtle.Turtle()
pen.penup()
pen.goto(-50, 0)
pen.write("Hello World", font=("Arial", 24, "normal"))
turtle.done()
A Trinket Turtle Graphics example that writes 'Hello World' on the canvas.
3
Draw a Square with Turtle
import turtle
pen = turtle.Turtle()
for _ in range(4):
pen.forward(100)
pen.right(90)
turtle.done()
Draws a square using Turtle Graphics.
4
Draw a Triangle with Turtle
import turtle
pen = turtle.Turtle()
for _ in range(3):
pen.forward(100)
pen.right(120)
turtle.done()
Draws an equilateral triangle using Turtle Graphics.
5
Print Numbers 1 to 10
for i in range(1, 11):
print(i)
Prints numbers from 1 to 10 using a for loop.
6
Simple Addition Function
def add(a, b):
return a + b
print(add(5, 3))
Defines a function to add two numbers and prints the result.
7
Draw a Circle with Turtle
import turtle
pen = turtle.Turtle()
pen.circle(50)
turtle.done()
Draws a circle using Turtle Graphics.
8
Hello User Input
name = input("Enter your name: ")
print(f"Hello, {name}!")
Asks for the user's name and prints a greeting.
9
Draw a Star with Turtle
import turtle
pen = turtle.Turtle()
for _ in range(5):
pen.forward(100)
pen.right(144)
turtle.done()
Draws a 5-pointed star using Turtle Graphics.
10
Simple While Loop Example
i = 1
while i <= 5:
print(i)
i += 1
Uses a while loop to count from 1 to 5.