0% found this document useful (0 votes)
7 views

02 if Statements

Uploaded by

pchambers
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

02 if Statements

Uploaded by

pchambers
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

If statements

Computer Science

© Nichola Wilkin Ltd 2019


www.nicholawilkin.com
1
Starter Start

INPUT num
What is
this flow Yes num > No
diagram 10?

showing OUTPUT OUTPUT


you? “Thank you” “Too low”

Stop

© Nichola Wilkin Ltd 2019


www.nicholawilkin.com
2
Lesson Objectives
All of you will…
▪Create a basic if statement using logical
operators
Most of you will…
▪Create an if…else statement and explain what a
flow diagram is showing
Some of you will…
▪Create your own flow diagrams using the
correct symbols
© Nichola Wilkin Ltd 2019
www.nicholawilkin.com
3
Flow diagrams Start

INPUT num1
• Flow diagrams show the
different routes a user
may take through a INPUT num2
program.
answer = num1 + num2
• So far all our programs
have been sequential
and each line would be OUTPUT answer
run, one after the other.
Stop
© Nichola Wilkin Ltd 2019
www.nicholawilkin.com
4
Flow diagrams Start

INPUT num1
There are a variety of
different symbols used:
INPUT num2
= Terminator
answer = num1 + num2
= Input or output
OUTPUT answer
= Process
(doing something)
Stop
© Nichola Wilkin Ltd 2019
www.nicholawilkin.com
5
Flow diagrams Start

INPUT num1

Write the Python INPUT num2

code for this flow


diagram. answer = num1 + num2

OUTPUT answer

Stop
© Nichola Wilkin Ltd 2019
www.nicholawilkin.com
6
Flow diagram Start

answer INPUT num1

INPUT num2

answer = num1 + num2

OUTPUT answer

Stop
© Nichola Wilkin Ltd 2019
www.nicholawilkin.com
7
Draw the flow diagram
for this Python program:

Input or
Terminator Process
Output
© Nichola Wilkin Ltd 2019
www.nicholawilkin.com
8
Answer Start

INPUT name

OUTPUT “Hello” name

INPUT num

answer = (num + 3)*2

OUTPUT answer

Stop

© Nichola Wilkin Ltd 2019


www.nicholawilkin.com
9
© Nichola Wilkin Ltd 2019
www.nicholawilkin.com
10
Are these statements true or
false?
1. 20>=21FALSE
2. 53!=82TRUE
3. 14<14 FALSE
TRUE
4. (2*5)==(8+2)
5. 3<=(4+2)TRUE
TRUE
6. 5//2>1
FALSE
7. 21%5!=1
FALSE
© Nichola Wilkin Ltd 2019
8. 46//5==8 11
www.nicholawilkin.com
More flow diagrams
Start
• This flow
diagrams
INPUT num
has another
symbol, the
decision Yes num > No
10?
diamond.
• What does OUTPUT
OUTPUT “Over 10”
it do? “Not over 10”

Stop
© Nichola Wilkin Ltd 2019
www.nicholawilkin.com
12
Decision diamond
Yes num > No
10?
OUTPUT OUTPUT “Not
“Over 10” over 10”
• A decision diamond has one input and two
possible outputs.
• It allows the program to take a different
route, depending on if it meets the criteria (in
this case if num is greater than 10).
© Nichola Wilkin Ltd 2019
www.nicholawilkin.com
13
© Nichola Wilkin Ltd 2019
www.nicholawilkin.com
14
How much do
you remember?

Create these
programs to
recap what
you have
learnt.

© Nichola Wilkin Ltd 2019


www.nicholawilkin.com
15
© Nichola Wilkin Ltd 2019
www.nicholawilkin.com
16
How much do
you remember?

Create these
programs to
recap what
you have
learnt.

© Nichola Wilkin Ltd 2019


www.nicholawilkin.com
17
Pop Quiz
1. Which shape is used to represent a
terminator in a flow diagram?
2. Which shape is used to represent a
process in a flow diagram?
3. Which shape is used to represent an
input or an output in a flow diagram?
4. Which shape is used to make a decision
in a flow diagram?
5. Why are lines indented in an if…else
statement?
© Nichola Wilkin Ltd 2019
www.nicholawilkin.com
18
Start

Plenary INPUT num1

INPUT num2
Create the Python
program for this answer = num1 + num2

flow diagram.
Yes answer No
> 10?
Now work together
as a class, to tell newAnswer = answer + 3 newAnswer = answer * 2
the teacher what
to type in to
OUTPUT newAnswer
create the same
program.
© Nichola Wilkin Ltd 2019 Stop 19
www.nicholawilkin.com

You might also like