🐍 Coding Intro

Scratch & Python Basics

⏱ 3 hr3 topicsInteractive
🎯 By the end: You can describe how Scratch builds programs from blocks, write a simple Python program that prints output, use int/float/string data, and do arithmetic in Python.

Programming means giving a computer step-by-step instructions. You'll meet two friendly ways in: Scratch, where you drag blocks together, and Python, where you type short, readable code. The best part — you can run real Python right here on the page.

1Scratch — coding with blocks

Scratch is a visual programming language where you build programs by snapping together coloured blocks — no typing of code needed. It's great for learning the ideas of programming.

TermMeans
SpriteA character/object you control on the stage
ScriptA stack of blocks that runs in order
BlocksMotion, Looks, Sound, Events, Control, Pen, etc. — each does one thing
StageThe area where your sprites act
The Pen blocks let a sprite draw lines as it moves — combine them with motion and repeat (loop) blocks to draw squares, triangles and patterns.
Key points
  • Scratch is block-based: you snap coloured blocks together instead of typing code.
  • A sprite is a character; a script is a stack of blocks that runs in order.
  • The Pen blocks make a sprite draw as it moves — good for shapes and patterns.

2Your first Python program

Python is a real, widely-used language with simple, readable syntax. The classic first program prints a message with the print() function:

print("Hello, World!")

Whatever you put inside the quotes is shown on screen. Press Run below to execute real Python — then change the message and run it again:

Python Playground▶ runs real Python
main.py
Output
Click Run to execute.
Key points
  • print("...") displays the text inside the quotes on screen.
  • Python is typed code (unlike Scratch's blocks) but is simple and readable.
  • Text inside quotes is called a string.

3Data types and arithmetic

Every value in Python has a data type. The three you need now:

TypeHoldsExample
intWhole numbers25
floatDecimal numbers3.14
string (str)Text in quotes"Vidaara"

You can store values in variables and do arithmetic with + - * / %. Run this and try changing the numbers:

Variables & arithmetic▶ runs real Python
main.py
Output
Click Run to execute.
Key points
  • Data types: int (whole numbers), float (decimals), string (text in quotes).
  • A variable stores a value: total = price * qty.
  • Arithmetic operators: + - * / and % (remainder).

★ Practical: code a little

Using the Python playgrounds above:

  1. Print your own name and class on two lines.
  2. Make two number variables and print their sum and product.
  3. Store a float (like a price) and a string (like an item) and print them together.
  4. In Scratch (if available), use Pen + repeat blocks to draw a square.

Ready for the chapter test?

Answer 5 questions. Score 60% or more to mark this chapter complete.

Start the test →

💡 Log in to save your progress and earn the certificate.