3. LESSON OUTCOMES
I can use variables in Python …
I can use while loops in Python …
4. VARIABLES
[ slide 3 ]
A variable is a space in the computer’s memory where we can
store data such as a number or text. The value can be
changed if required.
The box represents the space reserved in the computer’s memory
To create a
variable and give
it the value 42 we
write:
>>> my_number=42variable
name
42
The variable’s
value
Outcomes:
I can use variables in Python…
I can use while loops in Python …
5. >>> my_number=0
while my_number < 10:
print (I love coding in
Python)
my_number = my_number+1
The variable is called number
The = operator gives the variable
a value 0.
This line of code says ‘while the
variable called number is
less than 10 do the
following.
All of the code that is indented
after the colon is to be
repeated by the computer – it
loops through these two lines
of code until number is no
longer less than 10.
WHILE LOOPS
Outcomes:
I can use variables in Python…
I can use while loops in Python …
6. TASK 1 – USING WHILE LOOPS
[ slide 4 ]
Open the following file: While loop.
When the file is open enter your own print output in the
print function brackets.
>>> my_number=0
>>> while my_number < 10:
print("I love coding in Python!")
my_number = my_number+1
Outcomes:
I can use variables in Python…
I can use while loops in Python …
When you have completed the above code attempt Task 1 on worksheet 3.
7. MINI PLENARY
Look at the following code:
x=0
while x<5:
print('looping')
When do you think the code will stop
looping.
Outcomes:
I can use variables in Python…
I can use while loops in Python …
8. MAIN TASK 2
Have a go at completing
Tasks 2 and 3
on the worksheet.
Outcomes:
I can use variables in Python…
I can use while loops in Python …