year 7 lesson 3 variables and while loops

11
VARIABLES & WHI LE LOOPS LE S SON 3

Upload: tmoncrieff

Post on 23-Jun-2015

1.162 views

Category:

Education


5 download

DESCRIPTION

Lesson 3 - Variables and While Loops

TRANSCRIPT

Page 1: Year 7 lesson 3   variables and while loops

VARIA

BLES

& WHILE

LOOPS

L ES

SO

N 3

Page 2: Year 7 lesson 3   variables and while loops

LESSON OBJECTIVES

Learn to use variables and ‘while’ loops to get keyboard input from users.

Page 3: Year 7 lesson 3   variables and while loops

LESSON OUTCOMES

I can use variables in Python …

I can use while loops in Python …

Page 4: Year 7 lesson 3   variables and while loops

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=42my_numbervariable

name

42The variable’s value

Outcomes: I can use variables in Python… I can use while loops in Python …

Page 5: Year 7 lesson 3   variables and while loops

>>> my_number=0while 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 …

Page 6: Year 7 lesson 3   variables and while loops

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.

Page 7: Year 7 lesson 3   variables and while loops

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 …

Page 8: Year 7 lesson 3   variables and while loops

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 …

Page 9: Year 7 lesson 3   variables and while loops

WORKSHEET ANSWERS

Outcomes: I can use variables in Python… I can use while loops in Python …

Page 10: Year 7 lesson 3   variables and while loops

PLENARY

Can you explain what the program lines are doing?

Outcomes: I can use variables in Python… I can use while loops in Python …

Page 11: Year 7 lesson 3   variables and while loops

ANSWER

Outcomes: I can use variables in Python… I can use while loops in Python …