MG STUDENTS 13 Selection - Iteration

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 23

How do I interpret & understand problems & use a flowchart

Hardware &
Processing
help me write code? 1 School Network

2 Internet & WWW

Lesson intention: 3 DNS Packets TCP/IP

Communication, Networks & IT


4 Bandwidth & Latency

Show an understanding of selection, explain what is meant by iteration 5 You & Your Data

and the difference between for & while loops 6 Social Engineering

7 Computer Misuse

8 Prevent

9 Binary

Representation
Data & Data
10 A splash of colour
Grade Descriptors
1-2 I know what an algorithm is and I can express simple algorithms using symbols.
1-2 I know that computers need precise instructions.
1-2 I can show care and precision to avoid errors 11 Good vibrations
2-3 I know that algorithms are implemented on digital devices as programs.
2-3 I can design simple algorithms using loops, and selection i.e. if statements.
2-3 I can use logical reasoning to predict outcomes.
2-3 I can find and correct errors i.e. debugging, in algorithms. 12 Computational thinking
3-4 I can design solutions (algorithms) that use repetition and two-way selection i.e. if, then and else.

Algorithms
3-4 I can use flowcharts to express solutions.
3-4 I can use logical reasoning to predict outputs, showing an awareness of inputs.
4-5 I can design solutions by decomposing a problem and creates a sub-solution for each of these parts (decomposition). 13 Input, selection & data types
4-5 I know that different solutions exist for the same problem.
5-6 I know that iteration is the repetition of a process such as a loop.
5-6 I know that different algorithms exist for the same problem. 14 Procedures & Functions
5-6 I can represent solutions using pseudocode
5-6 I can identify similarities and differences in situations and can use these to solve problems (pattern recognition).
6-7 I know a recursive solution to a problem repeatedly applies the same solution. 15 Getting to know you
6-7 I know the notion of performance for algorithms and I know that some algorithms have different performance characteristics for the same task.

ramming & Development


7-8 I know that the design of an algorithm is distinct from its expression in a programming language.
7-8 I know where information can be filtered out in generalizing problem solutions (abstraction). 16 Loopy
7-8I can use logical reasoning to explain how an algorithm works.
8-9 I can design a solution to a problem that depends on solutions to smaller instances of the same problem (recursion).
17 Functions

18 Main Menu
Key Questions

The Summer Seven Key Words

t e n a t i o n ?
What is a variable?W ha t is c o nc a
Why do w W h at is s ele c tion?
e need da
ta types?
What is a sequence?

t co nt ro l led lo o p ?
What is a coun
What is a condition cont
rolled loop?

Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops
• These are the four different data types we are going to be looking at.
• Data types are the type (category) of data that your variable can hold

Boolean only has two possible Anwser_correct = False


Boolean outcomes: True or False. Light_on = True

A collection of characters, this does Name = Isabelle


String not have to be a word Username = Nick1991

Age = 34
Integer Whole numbers only

This used to store numbers with a


Cost = 9.99
decimal place. Real numbers are
Real sometimes referred to as floating
Pi = 3.14
Finishtime = 11.54
point numbers (float for short)

Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops
• These are the four different data types we are going to be looking at.
• Data types are the type (category) of data that your variable can hold
This used to store numbers with a
decimal place. Real numbers are Cost = 9.99
Real sometimes referred to as floating Pi = 3.14
point numbers (float for short) Finishtime = 11.54

A collection of characters, this does


String not have to be a word
E.g. mypassword2019

Integer Any whole number E.g. 14

Boolean A true or false value You being alive: True


• Declare Properties

Here we see a variable


being declared.

It is being given a
suitable name and the
data type is being
changed to a string.

This is because we are


going to give this
variable some characters
to deal with.
Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops
• Output Properties

We are able to output a variable We can add text to it by using


by simply writing the variable the & sign. This is called
name in the output window. concatenation. We are bringing
together two separate items.

Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops
• Output Properties

We are able to output a variable We can add text to it by using


by simply writing the variable the & sign. This is called
name in the output window. concatenation. We are bringing
together two separate items.
Concatenation = A series of
interconnected things.

Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops
Use Flowgorithm to
create a flowchart
that will ask the user
for their name, and
then use their name
in a message back
to them.

Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops
• Selection is when your algorithm has to make a decision.
• At a point in your program you may need to answer a question.
• A decision is when your flowchart has two or more paths to follow. We can
decide the outcome of the decision based on set variables or user inputs.
• We use mathematical operators in our flowcharts to help us make decisions.
• Below are some of the mathematical operators used in Flowgorithm

Operator Meaning Example Result Explanation


== Equal to 5 == 5 True 5 is equal to 5
< Less than 2 < 10 True 2 is less than 10
> Greater than 6 > 24 False 6 is not greater than 24
<= Less than or equal too 4 <= 4 True 4 is less or equal to 4
>= Greater than or equal too 22 >= 23 False 23 is not greater or
equal to 22

Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops
Make corrections to the table to make all of the example
statements true.

Operator Meaning Example Result Explanation


== Equal to 5 == 5 True 5 is equal to 5
< Less than 2 < 10 True 2 is less than 10
> Greater than 10 > 1 True 10 is greater than 1
<= Less than or equal too 4 <= 4 True 4 is less or equal to 4
>= Greater than or equal too 10 >= 10 True 10 is greater than or
equal to 10

Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops
• Familiar Language

In this example we can see how


selection works. You can see we have to
use a mathematical operator such as <
and > to describe less than and greater
than.

IF answer is over 16 say “old enough”

ELSE answer under 16 “not old enough”

We can add more selections to this and


it will become a nested if.

Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops
We can use more than one selection, this is called nested if. In this, the result of
selection statement moves to another selection statement, this can happen as many
times as we like. Here is an example of a nested if written out.

Ask ”how old you are?”

IF answer is over 16 say “go to college”

ELSE IF age under or equal 16 “Secondary”

ELSE answer under 16 “Primary”

Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops
Grade results A* A B C D E FAIL
90 80 70 60 50 40 >39
flowchart
Create a flowchart that will work out
what grade someone has achieved
based on the scores above.

You will have to use mathematical


operators to determine what grade
should be output. You will need to use
more than one selection statement.

Once you have done this, add a


screenshot of the flowchart, then
move onto the next slide and explain
how you have used selection, inputs,
and concatenation in your work.
Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops
Grade results A* A B C D E FAIL
90 80 70 60 50 40 >39
flowchart
Explain how you have used selection,
inputs, and concatenation in your work.
• Selection.
The selection is the initial if to see
whether or not the pupil would’ve
gotten and A*

• Inputs.
I used inputs for the name and score

• Concatenation
I used concatenation with ifs
embedded within other ifs
Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops
Think about boiling a kettle, does the
kettle boil FOR a set amount of time
or WHILE a condition has not been
met?

While loops are based on a condition


(condition controlled)

For loops repeat code for a specific


number of times (count controlled)

Repeating = iteration

Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops
Make this flowchart and explain below what it does.
It prints
1 turn
2 turn
3 turn
4 turn
5 turn

Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops
Count flowchart

• Create a flowchart that will count


down from 10 and when it reaches
zero the computer outputs blastoff.

• Use iteration in the countdown to


display each new number.
Loop flowchart

• Create a flowchart that asks the


user for their name and for a
number between 1 and 10.

• The program should then use a loop


to print out the name based on the
number that was entered above.

Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops
Make this flowchart and explain below what it does.

Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops
Make this flowchart and explain below what it does.

Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops
Using your understanding of
decomposition and while loops, now
create a piece of code that will check
how much petrol a car has.

If the petrol amount gets below 10


litres, a message should prompt the
user to top up their petrol. Screenshot here 

If the amount of petrol reaches zero,


the car will not work.

Lesson intention: Show an understanding of selection, explain what is meant by iteration and the difference between for & while loops

You might also like