wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

XRP: Variables & Functions

Total questions: 11

Worksheet time: 19mins

Name
Class
Date
1.

When do you want to use a variable?

a)

to hold a value

b)

to change values

c)

never

d)

to create a function

2.

Create a variable names velocity and set it to be 0

(a)  

3.

When would you use a while True loop?

4 lines
4.

Why make functions?

a)

easy to repeat code

b)

easier to read

c)

helps with variables

d)

let's you use if statements

5.

What are the parts of a function?

6.

Finish creating this function:

(a)   go_robot(velocity, time):

7.

Finish the code.

def run_robot(velocity, time):

drivetrain.set_speed(______, ______)

sleep(time)

(a)  

8.

You've created this function:

def run_robot(velocity, time):

drivetrain.set_speed(velocity, velocity)

sleep(time)

You want your robot to move for 20 secs. at a speed of 20 cm/s. Write the code to do that using the function

4 lines
9.

How would you make a function heading?

4 lines
10.

You want to create a function that tells a robot to go a certain distance and speed. What would be the parameters (the things in parenthesis)?

a)

speed

b)

distance

c)

time

d)

drivetrain

11.

How might you create a function that makes a robot drive a set distance?

Hint remember that distance = velocity*time

4 lines