Skip to content

3. Functions

For each of the tasks below, copy the code into EdPy and follow the instructions.

3.1 Beeping

Instructions

Complete the code below so that the Edison beeps 3 times.

Code - Click to expand
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#-------------Setup----------------

import Ed
Ed.EdisonVersion = Ed.V3
Ed.DistanceUnits = Ed.CM
Ed.Tempo = Ed.TEMPO_MEDIUM

#--------Your code below-----------

def beep_three():
    Ed.PlayBeep()
    Ed.TimeWait(500, Ed.TIME_MILLISECONDS)
    Ed.PlayBeep()
    Ed.TimeWait(500, Ed.TIME_MILLISECONDS)
    Ed.PlayBeep()
    Ed.TimeWait(500, Ed.TIME_MILLISECONDS)

3.2 Run Function

Instructions

Complete the code below so that it executes the function as intended.

Code - Click to expand
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#-------------Setup----------------

import Ed

Ed.EdisonVersion = Ed.V3

Ed.DistanceUnits = Ed.CM
Ed.Tempo = Ed.TEMPO_MEDIUM

#--------Your code below-----------

def drive_square():
    Ed.Drive(Ed.FORWARD, Ed.SPEED_3, 10)
    Ed.Drive(Ed.SPIN_RIGHT, Ed.SPEED_3, 90)
    Ed.Drive(Ed.FORWARD, Ed.SPEED_3, 10)
    Ed.Drive(Ed.SPIN_RIGHT, Ed.SPEED_3, 90)

drive_square()

3.3 Triangles

Instructions

Fix the code below to draw two triangles.

Code - Click to expand
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#-------------Setup----------------

import Ed

Ed.EdisonVersion = Ed.V3

Ed.DistanceUnits = Ed.CM
Ed.Tempo = Ed.TEMPO_MEDIUM

#--------Your code below-----------

def triangle():
    Ed.Drive(Ed.FORWARD, Ed.SPEED_3, 15)
    Ed.Drive(Ed.SPIN_RIGHT, Ed.SPEED_3, 120)
    Ed.Drive(Ed.FORWARD, Ed.SPEED_3, 15)

Ed.Drive(Ed.SPIN_RIGHT, Ed.SPEED_3, 120)
Ed.Drive(Ed.FORWARD, Ed.SPEED_3, 15)
Ed.Drive(Ed.SPIN_RIGHT, Ed.SPEED_3, 120)

triangle()
triangle()

3.4 Drawing a Square

Instructions

Create a function called forward_left(). This functions moves the Edison 10cm forwards and then spins to the left 90 degrees.

Create a second function called draw_square(). Draw square will use forward_left() to draw a square.

Make the Edison travel in a square.