Presentation is loading. Please wait.

Presentation is loading. Please wait.

GCSE Computing: Programming www.computerscienceuk.com GCSE Programming Remembering Python.

Similar presentations


Presentation on theme: "GCSE Computing: Programming www.computerscienceuk.com GCSE Programming Remembering Python."— Presentation transcript:

1 GCSE Computing: Programming www.computerscienceuk.com GCSE Programming Remembering Python

2 GCSE Computing: Programming www.computerscienceuk.com Activity 1 Review / Revise your understanding of: If – Else (selection) While loops Random number generation 3 mins

3 GCSE Computing: Programming www.computerscienceuk.com Iterations in Python The word iterate means loop (to keep doing something over and over again). Iterations are therefore loops and in Python there are two types of loop: For Loops - these are Finite (they run for a set number of times) While Loops - these are Infinite (they run forever – or until a condition is met) Does ‘x’ = 5? Start X = 0 X = X + 1 Execute Command Learning Objectives: Remember the following Programming Skills: -FOR Loops -WHILE Loops

4 GCSE Computing: Programming www.computerscienceuk.com For Loops in Python ‘For Loops’ in Python For Loops are set up using the following statement: for x in range ( n ): Lets take a look more closely… Does ‘x’ = 5? Start X = 0 X = X + 1 Execute Command Learning Objectives: Remember the following Programming Skills: -FOR Loops -WHILE Loops

5 GCSE Computing: Programming www.computerscienceuk.com For Loops in Python ‘For Loops’ in Python for x in range ( n ): The x is simply a variable. It could have any name. It is however a special kind of variable known as a ‘stepper’ The n represents the number of times that we want the loop to repeat itself for. If there was a 5 in the brackets, the loop would repeat 5 times. We must finish the statement with a colon Does ‘x’ = 5? Start X = 0 X = X + 1 Execute Command Learning Objectives: Remember the following Programming Skills: -FOR Loops -WHILE Loops

6 GCSE Computing: Programming www.computerscienceuk.com For Loops in Python ‘For Loops’ in Python for x in range ( 5 ): print(“Hello World ”, x) Hello World 0 Hello World 1 Hello World 2 Hello World 3 Hello World 4 0 Remember: In programming, we count from zero. So our stepper variable begins as a ‘0’. In this case, as soon as the variable becomes 5, the loop ends. 1 2 3 4 5 Learning Objectives: Remember the following Programming Skills: -FOR Loops -WHILE Loops

7 GCSE Computing: Programming www.computerscienceuk.com Demonstrations

8 GCSE Computing: Programming www.computerscienceuk.com For Loops in Python ‘For Loops’ in Python for x in range ( m, n,o ): Steps to move up in Starting Number Upper limit number – what the loop will stop at There are some other tools that we can use to customise our For Loop. We can change the starting number of our loop. We can state the steps we want to go up in (it doesn’t have to go up in 1s) Learning Objectives: Remember the following Programming Skills: -FOR Loops -WHILE Loops

9 GCSE Computing: Programming www.computerscienceuk.com Learning Check

10 GCSE Computing: Programming www.computerscienceuk.com While Loops in Python ‘While Loops’ in Python Lets take another look at WHILE loops …again (I know we reviewed this last lesson…) While Loops are set up using the following statement: while x 0: Lets take a look more closely… Does ‘x’ = 5? Start X = 0 Execute Command No Yes ==!=> < >= <= <> These are called conditions Learning Objectives: Remember the following Programming Skills: -FOR Loops -WHILE Loops

11 GCSE Computing: Programming www.computerscienceuk.com While Loops in Python ‘While Loops’ in Python while x n : The x is simply a variable. It could have any name. It is however a special kind of variable known as the ‘ most recent value ’ The n is represents a value that we want x to either equal, not equal, be greater than, etc. depending on the condition we want to use. E.g. n=5 and the condition while x != 5 (not equal to 5) then the loop would repeat until x equals 5. We must finish the statement with a colon Does ‘x’ = 5? Start X = 0 Execute Command No Yes == != > < Learning Objectives: Remember the following Programming Skills: -FOR Loops -WHILE Loops

12 GCSE Computing: Programming www.computerscienceuk.com While Loops in Python ‘While Loops’ in Python x = 0 while x == 0 : print(“Hello World”) Hello World Learning Objectives: Remember the following Programming Skills: -FOR Loops -WHILE Loops

13 GCSE Computing: Programming www.computerscienceuk.com While Loops in Python ‘While Loops’ in Python x = 0 while x != 5 : x = int(input(“Please type in a number”)) print(“Loop has ended”) Please type in a number: Remember: If you create a condition where a variable is being checked against an integer, you must remember to convert the variable’s input into an integer (e.g. int()) Please type in a number: 1 -5 122 5 Loop has ended Learning Objectives: Remember the following Programming Skills: -FOR Loops -WHILE Loops

14 GCSE Computing: Programming www.computerscienceuk.com Demonstrations

15 GCSE Computing: Programming www.computerscienceuk.com Commenting # Starting a line with a hash will turn your text into a comment. (It will be ignored by the program)

16 GCSE Computing: Programming www.computerscienceuk.com Tasks 1) Complete as many tasks as you can from the task sheet on ‘FOR and WHILE Loops ’. 2)By the end of the lesson – print out your best For Loop program and your best While Loop program & hand to me (name on your work please) NEED HELP? - borrow some headphones and watch the For Loop and While Loop videos on the department website HOMEWORK – practise working with loops


Download ppt "GCSE Computing: Programming www.computerscienceuk.com GCSE Programming Remembering Python."

Similar presentations


Ads by Google