# 7. Procedures again

We have already created procedures. Now to create procedures that we can pass data to.

## 7.1. Big Question

- How can I pass data to a procedure?

## 7.2. Key words

- Procedures
- Parameters

## 7.3. Introduction

So far we have procedures like `draw_square()`. However we have seen procedures such as `turtle.forward(100)`, so how do we make it so that we can pass data in such as the `100` above. Read on to find out.

## 7.4. Procedures again (Task 1)

Remember predict, then click run.

def say_greeting(): print ("Hello") say_greeting() say_greeting()

## 7.5. Procedures again (Task 2)

Now we want to tell it who to greet. For example `say_greeting("Mr D")`, should output `Hello Mr D`.

def say_greeting(name): print ("Hello " +name) say_greeting("Mr D") say_greeting("Student")

Now make some changes, and run again. Experiment, play, learn.

## 7.6. Procedures again (Task 3)

Now with turtles

import turtle def draw_triangle(size): for i in range (3): turtle.forward(size) turtle.left(120) draw_triangle(10) draw_triangle(20) draw_triangle(30)

Now make some changes, and run again. Experiment, play, learn.

## 7.7. Procedures again (Task 4)

Or with a loop.

import turtle def draw_triangle(size): for i in range (3): turtle.forward(size) turtle.left(120) for i in range(3): print (i) draw_triangle(10*i)

What went wrong? Now make some changes, and run again. Experiment, play, learn.

## 7.8. Procedures again (Task 5)

Procedures-2.1: In the code above, what does the number, that we pass to draw_triangle do?
- Tell the procedure the angle.
- No it draws triangles, the angle is always 120°.
- Tell the procedure the size.
- Yes, the number goes to turtle.forward, to tell it how far to move.
- Tell the procedure how many times to loop.
- No it draws triangles, always with 3 sides.
- Tell the procedure the shape.
- No this procedure only does triangles

## 7.9. Procedures again (Task 6)

Now to try a polygon procedure.

            Procedures-2.2: Rearrange to make it draw some polygonsimport turtle

    def draw_polygon(number_of_sides):
    ---
        for i in range(number_of_sides):
            turtle.forward(50)
            turtle.right(360/number_of_sides)
    ---
    for n in range(3,10):
        draw_polygon(n)

## 7.10. Procedures again (Task 7)

Now try it, and make some changes. Experiment, play, learn.

import turtle def draw_polygon(number_of_sides): for i in range(number_of_sides): turtle.forward(50) turtle.right(360/number_of_sides) for n in range(3,10): draw_polygon(n)

## 7.11. Procedures again (Task 8)

Fix this one. It should draw the polygons approximately the same size. But I forgot one thing. Where does the variable `size` go, in the procedure?

Clue look at `number_of_sides`. It appears 3 times, where? `size` should appear twice, where?

import turtle def draw_polygon(number_of_sides, size): for i in range(number_of_sides): turtle.forward(50) turtle.right(360/number_of_sides) for n in range(3,10): draw_polygon(n,200/n)
Next Section - 8. Challenges