<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Traverse a Square - Part 2 - Variables
In this notebook, we will introduce one of the most powerful ideas in programming
Step1:  Try changing the message in the previous code cell and re-running it. Does it behave as you expect?
You may remember from the Getting Started WIth Notebooks.ipynb notebook that if the last statement in a code cell returns a value, the value will be displayed as the output of the code cell when the cell contents have been executed.
If you place the name of a variable, or one or more comma separated variables, on the last line of a code cell, the value will be displayed.
What do you think the output of the following cell will be? Run the cell to find out.
Step2:  You can assign whatever object you like to a variable.
For example, we can assign numbers to them and do sums with them
Step3:  See if you can add the count of a new set of purchases to the number of items in your basket in the cell above. For example, what if you also bought 3 pears. And a bunch of bananas.
Making Use of Variables
Let's look back at our simple attempt at the square drawing program, in which we repeated blocks of instructions and set the numberical parameter values separately in each case.
Before we run the program, we need to load in the bits we need...
Step4:  The original programme appears in the code cell below. 
how many changes would you have to make to it in order to change the side length?
can you see how you might be able to simplify the act of changing the side length?
what would you need to change if you wanted to make the turns faster? Or slower?
HINT
Step5:  Using the above programme as a guide, see if you can write a programme in the code cell below that makes it easier to maintin and simplifies the act of changing the numerical parameter values.
Step6:  How did you get on?
How easy is is to change the side length now? Or find a new combination of the turn speed and turn angle to turn through ninety degrees (or thereabouts?). Try it and see...
Here's the programme I came up with
<ASSISTANT_TASK:>
Python Code:
# Create the message variable and assign the value "Hello World" to it
message="Hello World"
# Use the variable in a print statement
# The print statement retrieves the value assigned to the variable and displays the value
print(message)
Explanation: Traverse a Square - Part 2 - Variables
In this notebook, we will introduce one of the most powerful ideas in programming: the variable.
A variable is a container that we can reference by name that is associated with a particular value. The value is assigned to the variable using the the = operator, which we might read as is set to the value of.
For example, consider the following assignment statement:
python
message="Hello World"
Here, we create a named container message and put the value Hello World into it.
When we refer to the variable as part of another expression, we can then access the value it contains and use that in our expression, as the following example demonstrates:
End of explanation
message
Explanation: Try changing the message in the previous code cell and re-running it. Does it behave as you expect?
You may remember from the Getting Started WIth Notebooks.ipynb notebook that if the last statement in a code cell returns a value, the value will be displayed as the output of the code cell when the cell contents have been executed.
If you place the name of a variable, or one or more comma separated variables, on the last line of a code cell, the value will be displayed.
What do you think the output of the following cell will be? Run the cell to find out.
End of explanation
#Assign raw numbers to variables
apples=5
oranges=10
#Do a sum with the values represented by the variables and assign the result to a new variable
items_in_basket = apples + oranges
#Display the resulting value as the cell output
items_in_basket
Explanation: You can assign whatever object you like to a variable.
For example, we can assign numbers to them and do sums with them:
End of explanation
%run 'Set-up.ipynb'
%run 'Loading scenes.ipynb'
%run 'vrep_models/PioneerP3DX.ipynb'
Explanation: See if you can add the count of a new set of purchases to the number of items in your basket in the cell above. For example, what if you also bought 3 pears. And a bunch of bananas.
Making Use of Variables
Let's look back at our simple attempt at the square drawing program, in which we repeated blocks of instructions and set the numberical parameter values separately in each case.
Before we run the program, we need to load in the bits we need...
End of explanation
%%vrepsim '../scenes/OU_Pioneer.ttt' PioneerP3DX
import time
#side 1
robot.move_forward()
time.sleep(1)
#turn 1
robot.rotate_left(1.8)
time.sleep(0.45)
#side 2
robot.move_forward()
time.sleep(1)
#turn 2
robot.rotate_left(1.8)
time.sleep(0.45)
#side 3
robot.move_forward()
time.sleep(1)
#turn 3
robot.rotate_left(1.8)
time.sleep(0.45)
#side 4
robot.move_forward()
time.sleep(1)
Explanation: The original programme appears in the code cell below. 
how many changes would you have to make to it in order to change the side length?
can you see how you might be able to simplify the act of changing the side length?
what would you need to change if you wanted to make the turns faster? Or slower?
HINT: think variables...
End of explanation
%%vrepsim '../scenes/OU_Pioneer.ttt' PioneerP3DX
import time
#YOUR CODE HERE
Explanation: Using the above programme as a guide, see if you can write a programme in the code cell below that makes it easier to maintin and simplifies the act of changing the numerical parameter values.
End of explanation
%%vrepsim '../scenes/OU_Pioneer.ttt' PioneerP3DX
import time
side_length_time=1
turn_speed=1.8
turn_time=0.45
#side 1
robot.move_forward()
time.sleep(side_length_time)
#turn 1
robot.rotate_left(turn_speed)
time.sleep(turn_time)
#side 2
robot.move_forward()
time.sleep(side_length_time)
#turn 2
robot.rotate_left(turn_speed)
time.sleep(turn_time)
#side 3
robot.move_forward()
time.sleep(side_length_time)
#turn 3
robot.rotate_left(turn_speed)
time.sleep(turn_time)
#side 4
robot.move_forward()
time.sleep(side_length_time)
Explanation: How did you get on?
How easy is is to change the side length now? Or find a new combination of the turn speed and turn angle to turn through ninety degrees (or thereabouts?). Try it and see...
Here's the programme I came up with: I used three variables, one for side length, one for turn time, and one for turn speed. Feel free to try running and modifying this programme too...
End of explanation
<END_TASK>