Font size
WorksheetsXRP: Variables & Functions
Total questions: 11
Worksheet time: 19mins
When do you want to use a variable?
to hold a value
to change values
never
to create a function
Create a variable names velocity and set it to be 0
(a)
When would you use a while True loop?
Why make functions?
easy to repeat code
easier to read
helps with variables
let's you use if statements
What are the parts of a function?
parameters
defining the function
calling the function
Finish creating this function:
(a) go_robot(velocity, time):
Finish the code.
def run_robot(velocity, time):
drivetrain.set_speed(______, ______)
sleep(time)
(a)
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
How would you make a function heading?
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)?
speed
distance
time
drivetrain
How might you create a function that makes a robot drive a set distance?
Hint remember that distance = velocity*time
