Iteration and Selection

Slides:



Advertisements
Similar presentations
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Advertisements

Lesson 1 Sequencing.
Objective of the lesson Use Blockly to make a dice for Snakes and Ladders All of you will: – Make an image which displays when you press a button Most.
BBC MICRO:BIT Lesson 2 Variables and Lists. Variables When programming it is often necessary to store a value for use later on in the program. A variable.
Lesson 4 Accelerometer.
Lesson 5 Music.
GCSE COMPUTER SCIENCE Practical Programming using Python
Control Flow (Python) Dr. José M. Reyes Álamo.
Computer Science A-level
micro:bit for primary schools – mb4ps.co.uk
Objective of the lesson
BBC Microbit.
BBC Microbit.
micro:bit for primary schools – mb4ps.co.uk
Intro to Computer Science CS1510 Dr. Sarah Diesburg
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
BBC Microbit.
Learning to Code with the MicroBit
BBC Microbit.
Game Controller Lesson Three.
Lesson 4 Accelerometer.
BBC Microbit.
Global Challenge Fitness Friend Lesson 2.
BBC Microbit.
BBC Microbit.
Objective of the lesson
BBC Microbit.
BBC Microbit.
BBC Microbit.
BBC Microbit.
BBC Microbit.
Objective of the lesson
Global Challenge Flashing Wheels Lesson 3.
Game Controller Lesson Two.
Objective of the lesson
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Problem Solving Designing Algorithms.
Global Challenge Love Heart Lesson 3.
Global Challenge Walking for Water Lesson 2.
Global Challenge Love Heart Lesson 3.
Global Challenge Flashing Wheels Lesson 3.
Global Challenge Walking for Water Lesson 2.
Global Challenge Love Heart Lesson 3.
Global Challenge Love Heart Lesson 3.
Global Challenge Walking for Water Lesson 2.
micro:bit for primary schools – mb4ps.co.uk
Global Challenge Flashing Wheels Lesson 3.
Global Challenge Flashing Wheels Lesson 3.
Global Challenge Love Heart Lesson 3.
Global Challenge Walking for Water Lesson 2.
BBC Microbit.
Global Challenge Walking for Water Lesson 2.
Global Challenge Walking for Water Lesson 2.
Lesson 2 Variables and Lists.
Global Challenge Walking for Water Lesson 2.
Global Challenge Love Heart Lesson 3.
Python While Loops.
Global Challenge Love Heart Lesson 3.
Global Challenge Flashing Wheels Lesson 3.
WJEC GCSE Computer Science
Global Challenge Walking for Water Lesson 2.
Global Challenge Walking for Water Lesson 2.
Global Challenge Walking for Water Lesson 2.
Global Challenge Flashing Wheels Lesson 3.
Global Challenge Love Heart Lesson 3.
Iteration Learning Objective: to be able to design algorithms that use iteration.
Objective of the lesson
Computer Science A-level
Global Challenge Love Heart Lesson 3.
Global Challenge Flashing Wheels Lesson 3.
Presentation transcript:

Iteration and Selection Lesson 3 Iteration and Selection

Try the code out for yourself. Iteration We use iteration to prevent typing the same code out many times and to make our code more efficient. This example program uses a while loop to repeat the “Computer” “Science” “Rocks” message forever. The code that you want to repeat has to be indented after the while True: statement. Try the code out for yourself.

Place a screenshot of your code here. Activity 3.1 Create a program that displays your name and repeats it at 2 second intervals. Use the example code to help you. Place a screenshot of your code here.

Selection With selection the path through a program can be changed depending of the result of a condition. The conditions are written using if statements. This example program uses an if statement to check if either of the buttons on the micro:bit have been pressed. If button a is pressed a tick is displayed, if button b is pressed a cross is displayed. Try the code out for yourself.

Built In Images Here is a list of the built in images in Micro Python: Image.HEART Image.HEART_SMALL Image.HAPPY Image.SMILE Image.SAD Image.CONFUSED Image.ANGRY Image.ASLEEP Image.SURPRISED Image.SILLY Image.FABULOUS Image.MEH Image.YES Image.NO Image.TRIANGLE Image.TRIANGLE_LEFT Image.CHESSBOARD Image.DIAMOND Image.DIAMOND_SMALL Image.SQUARE Image.SQUARE_SMALL Image.RABBIT Image.COW Image.MUSIC_CROTCHET Image.MUSIC_QUAVER Image.MUSIC_QUAVERS Image.PITCHFORK Image.XMAS Image.PACMAN Image.TARGET Image.TSHIRT Image.ROLLERSKATE Image.DUCK Image.HOUSE Image.TORTOISE Image.BUTTERFLY Image.STICKFIGURE Image.GHOST Image.SWORD Image.GIRAFFE Image.SKULL Image.UMBRELLA Image.SNAKE Image.CLOCK12 # clock at 12 o' clock Image.ARROW_N ... # arrows pointing N, NE, E, SE, S, SW, W, NW (microbit.Image.ARROW_direction)

Place a screenshot of your code here. Activity 3.2 Change the example program to display different images when each of the buttons are pressed. Use the example code to help you. Place a screenshot of your code here.

Activity 3.3 Create a program that will play two different animations, one when button a is pressed and one when button b is pressed. Use this code as a starting point. Place a screenshot of your code here.

Try it out for yourself (you can change the names). Random The random module in Python can be used to generate random numbers or select random items from a list. This example program displays a random name from the list when the micro:bit is shaken. Try it out for yourself (you can change the names).

Place a screenshot of your code here. Activity 3.4 Using the example program as a starting point create a program that turns the micro:bit into an electronic dice (when shaken it should output a number between 1 and 6). Place a screenshot of your code here.