1 of 14

Lesson 6

Project

2 of 14

  • Understand how a sequence of code works
  • Understand what a function is
  • Understand what a function with an argument is
  • Understand how to create and update variables
  • Understand how to create loops with definite ranges
  • Understand how to capture user input
  • Understand how to ensure the right data types are used
  • Understand how to reuse code

By the end of this lesson, you will…

Learning Objectives

3 of 14

Creating a project

In this lesson, we shall use all of our knowledge to create a custom pattern generator using EduBlocks and Turtle

Can you remember all of the coding concepts that we learnt?

Lesson 6

4 of 14

Coding Concepts

Over the past five lessons we have learnt:

  • How to write a sequence
  • How to use loops
  • How to capture user input
  • How to work with data types
  • How to store data in a variable
  • How to make decisions using conditional statements
  • How to use functions to reuse code

Lesson 6

5 of 14

Starting the project

Before we start the project we need to:

  • Import the turtle module
  • Connect to Turtle
  • Create a screen
  • Set the screen colour to Black
  • Speed up the Turtle to 100!

Lesson 6

6 of 14

Starting the game

  • Would you like to play a game?
  • This is the question asked to the user before the sequence starts
  • If they answer “y” the code will run
  • But if they answer “n” or anything else, the else condition is activated and the game ends

Lesson 6

7 of 14

What happens if…?

If the player chooses to play, then any code inside the if condition is activated.

Inside the if condition we create a function to draw a star pattern.

If we run our code now, what will happen?

Note: Right now star does not have a parameter defined.

Lesson 6

8 of 14

Draw a circle

Here we create a function to draw a circle

But, what do we replace “?” with?

Is it the diameter of the circle?

The radius?

Or the circumference?

Lesson 6

9 of 14

What is the radius of a circle?

To set the radius of the circle…

  • We need to ask the user, via user input
  • Then ensure the value given is an integer
  • Save the answer to a variable called “number”

Why do we want the value to be an integer?

Lesson 6

10 of 14

Draw 4 stars

Using a loop is a smart move

We can write code once, and run it many times

Here we set the Turtle pen colour to “red” and then “blue, in between we call the star function

Lesson 6

11 of 14

8 Circles

To draw 8 circles we use another for loop

We set the pen colour to green, and then call the circle function, using the data saved in the number variable

Lesson 6

12 of 14

Complete Code Listing

Here is all of the code in EduBlocks.

Your teacher will now open the code and can zoom in for clarity.

Can you alter the code to

  • Draw another shape?
  • Ask the user how many circles to draw?
  • Put all of the code in a while True loop

Can you also add new features?

Lesson 6

13 of 14

  • How to create a full project using code from previous lessons
  • That code can be used for creative projects
  • That Sequence, Selection, Iteration, Assignment and Loops are key coding concepts

What have we learnt?

Plenary

14 of 14

Congratulations!

You have successfully completed six lessons with EduBlocks, learn how to write Python code with blocks and be creative!

Next lesson, we’ll test our knowledge with an end of unit assessment

Plenary