Keywords: Range Trace table Testing List Index Activities: To create a trace table for a small piece of code using a set of data. Create a trace table.

Slides:



Advertisements
Similar presentations
LOOPS Loops are lines of code that can be run more than one time. Each time is called an iteration and in for loops there is also an index that is changing.
Advertisements

Part 2.  Arrays  Functions  Passing Variables in a URL  Passing variables with forms  Sessions.
Starter  Identify the separate tasks to be performed in the programming task below (break it down into numbered sections).  A program is needed to prompt.
Lilian Blot CORE ELEMENTS COLLECTIONS & REPETITION Lecture 4 Autumn 2014 TPOP 1.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
7.5 Inverse Function 3/13/2013. x2x+ 3 x What do you notice about the 2 tables (The original function and it’s inverse)? The.
A Level Computing#BristolMet Session Objectives U2#S6 MUST identify different data types used in programming aka variable types SHOULD describe each data.
CS 127 Writing Simple Programs.  Stages involved  Analyze the problem  Understand as much as possible what is trying to be solved  Determine Specifications.
Lesson 3 – Creating a spreadsheet to monitor stock using information from your data capture form and your customer database. Then display your data in.
AE1205 Programming Python Quiz: so how do we generate Numbers 1 to 10? range( ) Numbers 5,10,15,20,25 to 100? range( ) Numbers 20,18,16, to 0? range( )
Python – Procedures If the same piece of code needs to be used several times we can use a loop - but only if those times are all together. If you need.
Functions. Warm Up Solve each equation. 1.2x – 6 = x = X + 29 = x – 5 – 4x = 17 x = 14 x = - 7 x = -15 x = 11.
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
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.
EXERCISE IN CLASS CHAPTER 2. PART 1 SEQUENCE SCENARIO 1 Write an algorithm for a C program, that prompts user to enter total number of umbrellas he/she.
Creating Table using LOOP By Adnan and M.Qazi Programmers.
Course A201: Introduction to Programming 09/30/2010.
Math – What is a Function? 1. 2 input output function.
CW-V1 SDD 0901 Principals of Software Design and Development Loops Starter: Water JugsWater Jugs.
More Python!. Lists, Variables with more than one value Variables can point to more than one value at a time. The simplest way to do this is with a List.
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.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
Write a function rule for a graph EXAMPLE 3 Write a rule for the function represented by the graph. Identify the domain and the range of the function.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
Computer Science 101 For Statement. For-Statement The For-Statement is a loop statement that is especially convenient for loops that are to be executed.
For loop. Exercise 1 Write a program to have the user input three (3) numbers: (f)rom, (t)o, and (i)ncrement. Count from f to t in increments of i, inclusive.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Lecture 9 For Loops.
(Monty) Python for loops Mr. Neat. Comparison JavaC++Python source code name.java.cpp.py Object Oriented? required optional functions/ methods ( bob.hide()
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.
Python Flow of Control CS 4320, SPRING Iteration The ‘for’ loop is good for stepping through lists The code below will print each element in the.
Python - Iteration A FOR loop is ideal if we know how many times we want to repeat. Try this code: for loopCounter in range(10): print(loopCounter) There.
COMPUTER PROGRAMMING Year 9 – lesson 1. Objective and Outcome Teaching Objective We are going to look at how to construct a computer program. We will.
More about Iteration Victor Norman CS104. Reading Quiz.
Trace Tables In today’s lesson we will look at:
Writing algorithms Introduction to Python.
Python - Iteration A FOR loop is ideal if we know how many times we want to repeat. Try this code: for loopCounter in range(10): print(loopCounter) There.
Topic: Iterative Statements – Part 1 -> for loop
Lesson 4 - Challenges.
7 - Programming 7P, Q, R - Testing.
Lesson 3 - Repetition.
ALGORITHMS & FLOWCHARTING II
Model Functions Input x 6 = Output Input x 3 = Output
شاخصهای عملکردی بیمارستان
Use proper case (ie Caps for the beginnings of words)
Chapter 9 Control Structures.
SLOPE = = = The SLOPE of a line is There are four types of slopes
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Learning Outcomes –Lesson 4
فرق بین خوب وعالی فقط اندکی تلاش بیشتر است
Lists in Python Creating lists.
Function Rules and Tables.
Suppose I want to add all the even integers from 1 to 100 (inclusive)
Computer Science G10 T \2017 T shaikhah AlZeyoudi
PYTHON: BUILDING BLOCKS Sequencing & Selection
A LESSON IN LOOPING What is a loop?
Python Basics with Jupyter Notebook
Lesson 2 – Band Manager The Shakes have recently launched their first single "Shake 'em Up". They have printed 2000 copies of the single and want to know.
Loops and Simple Functions
Errors.
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.
Variables, Constants, Assign.
CMPT 120 Lecture 10 – Unit 2 – Cryptography and Encryption –
Iteration – While Loops
2.1(b) Notes: Graphing Quadratic Functions
9 x 14 9 x 12 Calculate the value of the following: 1 7 × 5 =
Lesson 3.3 Writing functions.
Equations & Graphing Algebra 1, Unit 3, Lesson 5.
Presentation transcript:

Keywords: Range Trace table Testing List Index Activities: To create a trace table for a small piece of code using a set of data. Create a trace table for a given scenario and set of data. Write the Python code for the scenario. Test the program using trace table data. Lesson Objective: Use range in a loop. Introduce a simple number list. Use trace tables effectively to test output.

Syntax: allword=“December” partofword=allword[0:3] Slicing example: partofword=allword[0: 3] Starter : Slicing start end (end number not included).

Syntax: range(start,end) Loop example: for loopcounter in range(0, 10): print (loopcounter) Looping for a set number of times start end (end number not included).

Syntax: mylist=[1,2,3] firstitem=mylist[0] Loop example: mylist=[1,2,3,4,5] for loopcounter in range(0, 5): print (mylist[loopcounter]) Simple List end (end number not included). 0 4

Code Example Input: numberlist = [2,3,4,5] yournumber=0 numberfromlist=0 yoursum=0 for loopcounter in range(0,4): yournumber = int(input("Input a number: ")) numberfromlist=numberlist[loopcounter] yoursum=numberfromlist+yournumber print("Answer is : " + str(yoursum))

numberlist = [2,3,4,5] yournumber=0 numberfromlist=0 yoursum=0 for loopcounter in range(0,4): yournumber = int(input("Input a number: ")) numberfromlist=numberlist[loopcounter] yoursum=numberfromlist+yournumber print("Answer is : " + str(yoursum)) Code Example Trace Table VariableStart Value numberlist [2,3,4,5] loopcounter0 yournumber 0 numberfromlist 0 yoursum 0

for loopcounter in range(0,4): yournumber = int(input("Input a number: ")) numberfromlist=numberlist[loopcounter] mysum=numberfromlist+yournumber print("Answer is : " + str(mysum)) Trace Table Input: numberlist loopcounter yournumbernumberfromlist yoursumoutput [2,3,4,5] Answer is: Answer is: Answer is: 11 Answer is: 14 Input a number: 2 Answer is : 4 Input a number: 3 Answer is : 6 Input a number: 7 Answer is : 11 Input a number: 9 Answer is : 14

Activity 1 Input: loopcounter yournumber yoursumoutput Write a program: 1.Use For Loop and Range to loop 4 times. 2.Write code to enter a number. 3.Write a line of code to calculate the number you have entered times (x) 5. 4.Print result. 5.Create trace table. 6.Run code, input set numbers and compare output with your trace table.

Activity 2 Write a program: 1.Create a list with 4 numbers. 2.Use For Loop and Range to loop 4 times. 3.Write a line of code to times (x) next number in the list by Print the result. 5.Create a trace table. 6.Run code and compare output with your trace table. numberlist loopcounter numberfromlist yoursumoutput