Rectangle
Draws two frames of # at chosen places and in colours. Teaches writing at screen coordinates, colours, loops and your own function with parameters.
Open in Tokbit Level: Intermediate. Free in the browser, nothing to install, no account needed.
Run the example in Tokbit and step through it: before each step say what will happen and check it in the Variables panel. Then change it your way.
Flowchart
Python program
The same program as Python code. In Tokbit you see it when you switch from Diagram to Python above the flowchart.
"""Draws two frames out of #. Teaches a function with parameters."""
# Tokbit screen functions, not in plain Python:
from tokbit import (
cls, at, color, background, border, BLACK, WHITE, YELLOW, LIGHT_GREEN,
)
def frame(x: int, y: int, width: int, height: int):
"""A frame at x, y of the given width and height: top and bottom, then the sides."""
for i in range(width):
at(x + i, y)
print("#", end="")
at(x + i, y + height - 1)
print("#", end="")
for j in range(height):
at(x, y + j)
print("#", end="")
at(x + width - 1, y + j)
print("#", end="")
background(BLACK)
border(BLACK)
cls()
color(YELLOW)
# A function call: a frame from column 10 and row 5, 20 wide and 8 high.
frame(10, 5, 20, 8)
color(LIGHT_GREEN)
frame(4, 15, 32, 4)
color(WHITE)
at(12, 9)
print("Tokbit draws", end="")
at(0, 20)
Follow-up tasks
Tasks in which you change the example (with a model solution):