For Loop GCSE Computer Science – Python. For Loop The for loop iterates over the items in a sequence, which can be a string or a list (we will discuss.

Slides:



Advertisements
Similar presentations
Roles of Variables with Examples in Scratch
Advertisements

1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 7: Program flow control.
Chapter 4: Looping CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
Eliza the Chatterbox Year 9 Computing HLA
A revision guide for programming with python. 1.A program is a set of instructions that tells a computer what to do. 2.The role of a programmer is to.
A Level Computing#BristolMet Session Objectives U2#S6 MUST identify different data types used in programming aka variable types SHOULD describe each data.
October 4, 2005ICP: Chapter 4: For Loops, Strings, and Tuples 1 Introduction to Computer Programming Chapter 4: For Loops, Strings, and Tuples Michael.
CS 127 Writing Simple Programs.  Stages involved  Analyze the problem  Understand as much as possible what is trying to be solved  Determine Specifications.
Python File Handling. In all the programs you have made so far when program is closed all the data is lost, but what if you want to keep the data to use.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 6: Variables and constants.
Python Repetition. We use repetition to prevent typing the same code out many times and to make our code more efficient. FOR is used when you know how.
Lesson 4 Using Variables in Python – Creating a Simple ChatBot Program.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Graphical User Interface You will be used to using programs that have a graphical user interface (GUI). So far you have been writing programs that have.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 8: Fun with strings.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
My Python Programmes NAME:.
Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there.
Iteration. Iteration: Review  If you wanted to display all the numbers from 1 to 1000, you wouldn’t want to do this, would you? Start display 1 display.
Count Controlled Loops (Nested) Ain’t no sunshine when she’s gone …
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
CS 101 – Oct. 7 Solving simple problems: create algorithm Structure of solution –Sequence of steps (1,2,3….) –Sometimes we need to make a choice –Sometimes.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
Controlling Program Structures. Big Picture We are learning how to use structures to control the flow of our programs Last week we looked at If statements.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 10: Files.
Input, Output and Variables GCSE Computer Science – Python.
Computer Science A-level
Introduction to Programming
Data Types and Conversions, Input from the Keyboard
Lesson 4 - Challenges.
Selection and Python Syntax
GCSE COMPUTER SCIENCE Practical Programming using Python
Think What will be the output?
Do it now activity Green pen activity in books.
Learning to Program in Python
Fill the screen challenge!
Use proper case (ie Caps for the beginnings of words)
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Learning Outcomes –Lesson 4
Lesson Aims Vocabulary In this lesson you are going to:
Introduction to Programming
Python Lessons 9 & 10 Mr. Husch.
Computer Science G10 T \2017 T shaikhah AlZeyoudi
Python 19 Mr. Husch.
PYTHON: BUILDING BLOCKS Sequencing & Selection
See requirements for practice program on next slide.
Python Lesson’S 1 & 2 Mr. Kalmes.
Python Basics with Jupyter Notebook
Input a number and print its table, using FOR loop.
Introduction to Computer Science
Print the following triangle, using nested loops
Python Inputs Mr. Husch.
Python 19 Mr. Husch.
GCSE Computing:: While Loops
Python 10 Mr. Husch.
Just Basic Lessons Mr. Kalmes.
Introduction to Programming
Basic 9 Mr. Husch.
Arrays & Loops.
What you need to do… Drag the pieces of code into the correct order like you can see in the EXAMPLE below. print ( “ int input ) = + Hello world chr ord.
Arrays & Loops.
Iteration – While Loops
Lecture 20 – Practice Exercises 4
GCSE Computing.
Lecture 20 – Practice Exercises 4
Computer Science A-level
Python Creating a calculator.
Presentation transcript:

For Loop GCSE Computer Science – Python

For Loop The for loop iterates over the items in a sequence, which can be a string or a list (we will discuss lists later in this lesson) each time assigning the values in this sequence to a given variable. Note that the terminating condition is that we are at the end of the list.

For Loop The for loop is used as shown below: for ___ in range(___): code to be run here more code to be run here this code is not in the for loop

For Loop The for loop is used as shown below: for ___ in range(___): The first blank line must be replaced with a variable that keeps track of how many times the loop has run. The second blank line must be replaced with a number of times to loop.

For Loop The for loop is used as shown below: for ___ in range(___): for x in range (10): print (x) for pizza in range (99): print (pizza)

Counter The counter variable in Python starts from 0. for x in range (9): print (x) What do you think this will print?

For Loop – Example for x in range (10): print (“Mr Selwood”) ####################################### for pizza in range (5): print (pizza) ###################################### print (“Eight Times Table”) for x in range (10): print (x * 8)

Different Values You can change the start value of the for loop as shown below: for x in range(5, 10): print (x) What do you think this will print?

Different Values You can change the step value of the for loop as shown below: for x in range(5, 100, 10): print (x) What do you think this will print?

Individual Tasks For each of the following tasks: Use Python (IDLE) to code the solution. Copy and paste your solution into this PowerPoint Presentation. You can add additional slides!

1. Write a program to print the numbers one to twenty.

2. Write a program to print the six times table.

3. Ask the user to input a number. Print the times table for that number.

4. Ask the user for their age. Print “Happy Birthday” for every year of their age.