![Page 1: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/1.jpg)
PROGRAMMINGIn
Lesson 5
![Page 2: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/2.jpg)
RECAP
Complete the starter activity
![Page 3: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/3.jpg)
OBJECTIVES Understand how to use looping statement (while) Understand to use the break statement Understand the development process of flow charts to
comments to code
OUTCOMES All-Level 4 written code using while - with help
developed programs using pseudo code
Most-Level 5 Be able to write a these with little help.
Some-Level 6 Independently write these and adapt them and complete the extension tasks.
![Page 4: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/4.jpg)
LOOPS
You might remember this code from your truth table of last lesson. It is part of the function that got the user input.
It uses a while statement to keep asking the user to input a value until it is one of the required values.
![Page 5: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/5.jpg)
WHILE STATEMENT
while expression : statement 1 statement 2 statement 3
Statements are executed while the expression is true
Notice the indentation – this defines
the statements that are in the while statement
Don’t forget the full colon
![Page 6: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/6.jpg)
WRITE A LOOPY PROGRAM – PSEUDO CODE
Write a program that asks the user for a number and counts down to 1 displaying each number as it goes.
a=int(a) – converts number a to an integer
You have the rest of the knowledge.
Extension:Get you program to calculate the factorial of the number.
Hint: factorial of 4 is 4 * 3 * 2 * 1.
start
Ask user for a number
Convert to integer
Display number
Subtract one
Is number > 0
Yes
endNo
• Write the pseudo code for the program.
• We will then write the program comments from this pseudo code
• We will then fill in the code for each comment.
![Page 7: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/7.jpg)
end
WRITE A LOOPY PROGRAM - COMMENTS
Is number > 0
start
Ask user for a number
Convert to integer
Display number
Subtract one
Yes
No
![Page 8: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/8.jpg)
WRITE A LOOPY PROGRAM - CODE
Extension:Get you program to calculate the factorial of the number. Hint: factorial of 4 is 4 * 3 * 2 * 1.
![Page 9: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/9.jpg)
With your classmate you have 2 mins to discuss…
What was most difficult in the program
What was most fun
What was the boring part
CLASS DISCUSSION
![Page 10: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/10.jpg)
WHILE STATEMENT BREAK
while expression : statement 1 statement 2
breakThis command quits from the while statement – even
if the expression is still true.
Statements are executed while the expression is true
Notice the indentation – this defines
which statements are in the
while statement
![Page 11: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/11.jpg)
GUESS THE NUMBER – VERSION 2 Remember this – guessing a random number….
![Page 12: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/12.jpg)
I want you to make it even better
Give the user 6 chances to guess the number - use while statement
Let them know if their guess is too high - if statement
Let them know if their guess is too low - if statement
GUESS THE NUMBER – VERSION 2
![Page 13: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/13.jpg)
WHAT DO WE NEED TO CHANGE
![Page 14: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/14.jpg)
Set guesses to zero
Exit from while loop
Add 1 to guesses
User has a guess
No
NoGuess
= numbe
r
Yes
NoGuess
> numbe
r
Tell user too highYes
Tell user too low
Guess <
number
Yes
Guesses > 6No
Yes Exit from while loop
You have previously written most of this program.
All you need to do is write the new section
![Page 15: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/15.jpg)
Set guesses to zero
Exit from while loop
Add 1 to guesses
User has a guess
No
No
Guess =
number
Yes
NoGuess >
number
Tell user too high
Yes
Tell user too low
Guess <
number
Yes
Guesses > 6
No
Yes Exit from while loop
![Page 16: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/16.jpg)
WRITE THE CODE
![Page 17: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/17.jpg)
EXTENSIONS
Make the random number range from 1 to 30
Let them know the random number if they fail to guess it.
![Page 18: PROGRAMMING In Lesson 5. RECAP Complete the starter activity](https://reader035.vdocuments.us/reader035/viewer/2022062716/56649dbe5503460f94ab0dc6/html5/thumbnails/18.jpg)
PLENARY
Complete the Lesson 5 plenary Quiz