Head office, Rana Pratap Bagh, Delhi011 2721 1512+91 97116 99511

Science project idea

Python turtle drawing of the Indian tricolour with chakra

A function draws filled rectangles and a loop draws 24 spokes, so the flag is built from geometry and code. It shows how functions and loops reduce repetition.

What it shows

A function draws filled rectangles and a loop draws 24 spokes, so the flag is built from geometry and code. It shows how functions and loops reduce repetition.

The science

The flag is three equal horizontal stripes in a ratio of 3 to 2, with a navy chakra of 24 spokes in the centre. A full circle is 360 degrees, so 24 spokes are 15 degrees apart. A function with parameters for position, size and colour lets one block of code draw all three stripes. The begin_fill and end_fill commands colour the shape.

Materials

Cost: free. Many items come from home or from waste; spare parts such as LEDs, motors and wire are in the store.

  • A computer, laptop or phone with a browser (free)
  • Python 3 with IDLE, or the free Thonny editor, or an online Python runner (all free)
  • Colour values: saffron #FF9933, white #FFFFFF, green #138808, navy blue #000080
  • A notebook and a pencil

Safety

This project uses safe, everyday materials. Still, read the rules below with a parent before you start.

Never use mains electricity: power models with cells, batteries or a low-voltage adapter. Sharp and hot tools, flames and lab chemicals need an adult or your teacher beside you. Keep magnets, button cells and small parts away from young children, and wash your hands after making.

All the safety rules

Step by step

8 steps. Do them in order, and test each part before you go on to the next. Write what you notice in a notebook as you go.

  1. Create flag.py with import turtle, then t = turtle.Turtle(), t.speed(0) and t.hideturtle().

  2. Define def rect(x, y, w, h, colour): and inside it use t.penup(), t.goto(x, y), t.setheading(0), t.pendown(), t.color(colour), t.begin_fill().

  3. Still inside the function add for _ in range(2): with t.forward(w), t.right(90), t.forward(h), t.right(90) indented, then t.end_fill().

  4. Call rect three times for a flag 300 wide and 200 high starting at x = -150: rect(-150, 100, 300, 66.6, "#FF9933"), rect(-150, 33.4, 300, 66.6, "white") and rect(-150, -33.2, 300, 66.6, "#138808").

  5. Draw the chakra circle: t.penup(), t.goto(0, -30), t.color("#000080"), t.pendown(), t.circle(30).

  6. Draw 24 spokes with for i in range(24): then t.penup(), t.goto(0, 0), t.setheading(i * 15), t.pendown(), t.forward(30).

  7. Finish with turtle.done(). Run it and check that the stripes are equal and the chakra is centred.

  8. Draw an outline around the white stripe, so it is visible on a white window, with the pen colour grey.

What you should see

The window shows a tricolour with equal saffron, white and green stripes and a navy chakra with 24 evenly spaced spokes.

Viva questions

A teacher or a judge will ask how it works. Try to answer each question before you open it, then compare.

1Why are spokes 15 degrees apart?

360 divided by 24 spokes is 15 degrees.

2What does the function avoid?

Writing the same rectangle code three times.

3What do begin_fill and end_fill do?

They fill the shape drawn between them with the current colour.

4What is the shape ratio of the flag?

Three units of length to two units of height.

Free ebook: Viva Questions for Science Projects

Take it further

Make the flag size a variable so one change redraws the whole flag at double or half size.

Change one thing, measure what happens, and add a table or chart of your readings: that is what turns a model into your own investigation.

Free ebooks for this project

WhatsApp us