Skip to content

2. Task 2 - Variables

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

2.1 Fixing Code

Instructions

The code below doesn't quite work. Add a variable to line 12 to make it work.

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

import Ed

Ed.EdisonVersion = Ed.V3

Ed.DistanceUnits = Ed.CM
Ed.Tempo = Ed.TEMPO_MEDIUM
#--------Your code below-----------

length = 10

Ed.Drive(Ed.FORWARD, speed, length)
Hint - Click to expand

The name of the variable has to match something on line 13.

2.2 Variable Names

Instructions

Complete the code below. Read the code and use the variable names to determine what to do:

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

Ed.EdisonVersion = Ed.V3

Ed.DistanceUnits = Ed.CM
Ed.Tempo = Ed.TEMPO_MEDIUM
#--------Your code below-----------

length_1 = 9
length_2 = 5
length_3 = length_1 + length_2

Ed.Drive(Ed.FORWARD, Ed.SPEED_5, sum)
Ed.TimeWait(length_2, Ed.TIME_SECONDS)
Ed.Drive(Ed.FORWARD, Ed.SPEED_5, difference)
Ed.TimeWait(length_2, Ed.TIME_SECONDS)
Ed.Drive(Ed.FORWARD, Ed.SPEED_5, product)

2.3 Square Driving

Instructions

Using variables to set the length, angle and speed – create a program that moves the Edison in a square.