Presentation is loading. Please wait.

Presentation is loading. Please wait.

3.1.3 Program Flow control Structured programming – SELECTION in greater detail.

Similar presentations


Presentation on theme: "3.1.3 Program Flow control Structured programming – SELECTION in greater detail."— Presentation transcript:

1 3.1.3 Program Flow control Structured programming – SELECTION in greater detail

2 What were the 3 building blocks of structured programming?

3 Lesson outcomes Be able to describe the basic building blocks of coded solutions in particular - SELECTION Be able to write create flow charts and pseudocode to represent SELECTION when solving a problem.

4 Quick one - SEQUENCE: Write me a definition of what a sequence is: Action 1 Action 2 Action 3

5 SELECTION Go on – what is it

6 SELECTION Selection or ‘conditional statements’ When using the IF statement, we test to see if one condition is true or false. It will only execute if the condition is TRUE

7 SELECTION Selection or ‘conditional statements’ Really simple example If 5>2: print (“5 is larger”) 5 is larger

8 SELECTION Selection or ‘conditional statements’ Extension of the IF Statement; THEN it will execute a process if it is true or ELSE another process if it is false; Start Condition true? Action 2Action 1 noyes ThenElse

9 SELECTION – pseudocode Write me some pseudocode for a short (5 lines or so) program that: 1.Identifies a variable month and assign it “September” 2.If its length is greater than 10 characters then get it to return a message if its greater and a message if less

10 SELECTION – pseudocode Month = “September” If len(month) > 10 print(month + “ has more than 10 characters”) Else: print(month + “ has less than ten characters”)

11 In the exam 2015 Why are we writing this sir? Because we are designing and planning NOT creating the code. You must be able to express ideas using pseudocode. You will be asked

12 SELECTION Selection or ‘conditional statements’ Extension of the IF ELSE statement: ELIF. Will execute a process if it meets one of the conditions if expression1: Print statement(s) elif expression2: print statement(s) elif expression3: Print statement(s) else: statement(s)

13 Challenge Design with flowchart + pseudocode a short program that takes a mark entered by the user and the program assigns it a GRADE. 90 – 100 = A* 80 – 89 = A 70 – 79 = B 60 – 69 = C Etc etc

14 Give your solution to another person: Can they create the program you have written?

15 CASE statement This last ELIF is an alternative to the CASE statement used in other programs: IF statementIF...THEN...ELSECASE STATEMENT IF (Pay < £10K) Tax Rate = 0% IF (Pay > £40K) Tax Rate = 40% ELSE Tax Rate = 20% END IF CASE Pay OF <£10: THEN Tax Rate = 0% <£40: THEN Tax Rate = 20% <£150: THEN Tax Rate = 40% >£150: THEN Tax Rate = 50% END CASE

16 Keywords and terms in this lesson Selection IF IF...THEN...ELSE ELIF or CASE

17 exam = int(input("enter mark ")) if exam > 90: print ("A*") elif exam > 80: print("A") elif exam > 70: print ("B") elif exam > 60: print("C") else: print ("D")


Download ppt "3.1.3 Program Flow control Structured programming – SELECTION in greater detail."

Similar presentations


Ads by Google