Introduction to Programming with Python Session 3 Notes

Size: px
Start display at page:

Download "Introduction to Programming with Python Session 3 Notes"

Transcription

1 Introduction to Programming with Python Session 3 Notes Nick Cook, School of Computing Science, Newcastle University Contents 1. Recap if statements Iteration (repetition with while loops) Introduction to functions Exercises and challenges Resources Recap if statements In IDLE, open a new window and save file as ifrecap.py Type, run and test the following examples. Note the block structure. Ask for appropriate test values: case at the boundary of the condition, normal and unexpected (or exceptional) cases. Example 1: if else Test a condition, do one set of actions if it is true, otherwise do another set of actions. x = int(input('give me a number: ')) if x < 0: print(x, 'is negative') else: print(x, 'is positive') Test with 0, 1, - 1, '1' Example 2: if elif else Test a condition, do one set of actions if it is true. If it is not true but some other condition is true, do another set of actions. If neither condition is true, do another set of actions. c = input('give me a colour: ') if c == 'purple': print('i like', c) elif c == 'red': print('i prefer', c) else: print("i don't like", c) Test with 'purple', 'red', 'black', any other string Newcastle University,

2 Example 2: if by itself Test a condition and do one set of actions if it is true, otherwise do nothing. n = int(input('give me a big number: ')) if n <= 100: print(n, 'is not a big number') Test with 99, 100, 101, '2000' Example 3: nested if to combine two conditions Test a condition, if it is true, test another condition, and then do something if both are true. issunny = input('is it sunny (y/n)? ') isholiday = input('is it a holiday (y/n)? ') if issunny == 'y': print('it is sunny') if isholiday == 'y': print('wear shorts') Test with (y, y), (y, n), (n, y) The above nested if is essentially asking whether two conditions are true and only performing an action if both are true. This is the equivalent of a logical and both conditions must be true to perform an action. Example 4: using and to combine conditions and avoid nested if The use of a nested if is error prone. Imagine if more than two conditions must be true to perform an action, we would have to make sure each if statement were indented to the right level to achieve the desired result. This also obscures the logic of the program. We have to read down multiple nested if statements to understand the combination of conditions that must be true for the whole condition to be true. We can use the logical and to combine conditions in a clearer and less error prone way. For example in the following, the overall condition is met if the number input is both greater than or equal to 1 and less than 11 (in the range 1 to 10). m = int(input('give me number between 1 and 10: ')) if m >= 1 and m < 11: print('well done! You gave me:', m) Test with 0, 1, 9, 10, 11. See the logical operator table in Section 6 of the notes for Session 2 for the truth table for the and operator. Example 5: using or to avoid code duplication Consider following code: c = input('give me a colour: ') if c == 'red': Newcastle University,

3 print('i like that colour') elif c == 'green': print('i like that colour') else: print("i don't like that colour") The string 'I like that colour' will be output whether the input is 'red' or 'green'. We are duplicating code because more than one condition can lead to the same action. In this case we can use the logical or operator to simplify the code. c = input('give me a colour: ') if c == 'red' or c == 'green': print('i like that colour') else: print("i don't like that colour") As with the and operator, the or operator simplifies the code and makes the logic more obvious. The code is less error prone as a result. In this case, just one of a number of different conditions has to be true to perform some action. See the logical operator table in Section 6 of the notes for Session 2 for the truth table for the or operator. 2. Iteration (repetition with while loops) Use iteration to avoid repeating ourselves. Want to type a sequence of code and then have the program repeat it for us, rather than type (or even copy and paste) the sequence multiple times. Note, copy and paste is less error prone than repeat typing. Nevertheless, it can still lead to mistakes, e.g. if we change our minds about how many times some code must be executed. A while loop is one form of iteration that repeats a block of code as long as some condition is true. On whiteboard: Instead of: # execute code # execute code # execute code Use a while loop: while condition: # execute code Together as a class work through the first exercise in Section 3.2a of Mark Clarkson's book (p. 15). Class exercises Do second exercise in section 3.2a of the book (note there is a bug in the code in the book comparing a number/integer value to a string value will always be False) Newcastle University,

4 Do challenge 13 in the first booklet of Python Programming Challenges using a while loop. Hint: need time and random modules (see Section 3 of notes for Session 2) and need to iterate enough time for the program to take 30 seconds in total Do challenge 15 Together as a class work through repetition in turtle, saving code in shapes.py. Work through and explain versions 1, 2 and 3 below in turn. Ask class how to construct version 2, which may lead to different termination condition for the while loop. Explain the rationale for using the sidestodraw in the termination condition in version 3. Also give brief overview of the turtle module and calling functions of a turtle. import turtle # version 1 with code duplication # version 2 with while loop turtle.color('red') while sidestodraw > 0: sidestodraw = sidestodraw - 1 # version 3: changing sidestodraw also changes the angle # which means we can draw different shapes by changing # sidestodraw while sidestodraw > 0: # the following are needed to terminate turtle drawing window = turtle.screen() window.exitonclick() Newcastle University,

5 In vesion 3 above, just change the value of sidestodraw to 3 to draw a triangle or to 5 to draw a pentagon or to 6 to draw a hexagon etc. Ask class to experiment with different values for sidestodraw. 3. Introduction to functions Reusing code, putting a unit of work into a separate function (or procedure) and using it again wherever necessary. Also like sub- routines, breaking up a program into smaller component parts. Do 3.3a from book (p. 19) with class, save to file firstfunction.py. Function with more than one parameter Do following nsquared_plus_n function with class, save to file nsquaredplusn.py # function definition def nsquared_plus_n(nsquared, n): print(nsquared, '+',n,'=',nsquared + n) # main program counter = 0 while counter < 21: nsquared_plus_n(counter ** 2, counter) counter = counter + 1 Turtle draw a square function Re- open myshapes.py from Section 2 and do drawsquare function with class: Delete all code but version 3, so left with: import turtle while sidestodraw > 0: window = turtle.screen() window.exitonclick() Modify as follows: import turtle # function definition def draw_square(): while sidestodraw > 0: Newcastle University,

6 sidestodraw = sidestodraw - 1 # main program draw_square() window = turtle.screen() window.exitonclick() Class exercises create a draw_triangle function and draw a red triangle create a draw_hexagon function and draw a blue hexagon The resulting program should be: import turtle # function definitions def draw_square(): def draw_triangle(): sidestodraw = 3 sidestodraw = sidestodraw - 1 def draw_hexagon(): sidestodraw = 6 sidestodraw = sidestodraw - 1 # main program draw_square() turtle.color('red') draw_triangle() Newcastle University,

7 turtle.color('blue') draw_hexagon() window = turtle.screen() window.exitonclick() Question: what is the problem with the above code? Answer: code duplication the only difference between draw_square, draw_triangle and draw_hexagon is the value of sidestodraw, which is fixed/hard- coded in each function. Together with class develop a draw_shape function that can draw any equilateral shape. For draw_shape version 1 (parameterised with sidestodraw), take the draw_hexagon function, rename it to draw_shape, parameterise with sidestodraw, and delete the line that gives sidestodraw the value 6. def draw_shape(sidestodraw): draw_shape is a function that will draw any regular polygon (equilateral and equiangular) with sides of length 100. To draw different shapes just call the function with different values for the sidestodraw, e.g: # green square draw_shape(4) # red triangle turtle.color('red') draw_shape(3) # blue pentagon turtle.color('blue') draw_shape(5) Version 1 of draw_shape will only draw shapes with a fixed line length of 100. To draw shapes with different line lengths, add a parameter. Version 2 of draw_shape is called with a a number of sides to draw and a line length: def draw_shape(sidestodraw, linelength): turtle.forward(linelength) Newcastle University,

8 Now we can draw shapes with different line lengths: # blue square, line length 100 turtle.color('blue') draw_shape(4, 100) # red triangle, line length 150 turtle.color('red') draw_shape(3, 150) # green pentagon, line length 50 draw_shape(5, 50) Question: what happens when the number of sides to draw is less than 3? Class exercises Change the draw_shape function to print a message to say that sidestodraw is too small for a suitable value of sidestodraw and only draw a shape if sidestodraw is greater than the value. Consider which other fixed value in the function could be parameterised to allow us to control the size of the shape. Change the function accordingly. 4. Exercises and challenges From Mark Clarkson's Introduction to Python: Section 3.2a, 3.2f challenge using a while loop, 3.3a, 3.3b and 3.3c From Python Programming Challenges: challenges 13 (using a while loop), 15 and 16 From Python Programming Challenges Book 2: challenges 2.6, 2.7 and Resources Other material from Newcastle University Introduction to Python CPD: ython Mark Clarkson's Introduction to Python resources including textbook, workbooks, example code and GCSE controlled assessment: resources.zip Other Python resources: Python Web site: Newcastle University,

ESCI 386 Scientific Programming, Analysis and Visualization with Python. Lesson 5 Program Control

ESCI 386 Scientific Programming, Analysis and Visualization with Python. Lesson 5 Program Control ESCI 386 Scientific Programming, Analysis and Visualization with Python Lesson 5 Program Control 1 Interactive Input Input from the terminal is handled using the raw_input() function >>> a = raw_input('enter

More information

Turtle Power. Introduction: Python. In this project, you ll learn how to use a turtle to draw awesome shapes and patterns. Activity Checklist

Turtle Power. Introduction: Python. In this project, you ll learn how to use a turtle to draw awesome shapes and patterns. Activity Checklist Python 1 Turtle Power All Code Clubs must be registered. By registering your club we can measure our impact, and we can continue to provide free resources that help children learn to code. You can register

More information

Algorithms Abstraction

Algorithms Abstraction Algorithms Abstraction Instructions and answers for teachers These instructions should accompany the OCR resource Algorithms - Abstraction activity which supports OCR GCSE (9 1) Computer Science The Activity:

More information

Which shapes make floor tilings?

Which shapes make floor tilings? Which shapes make floor tilings? Suppose you are trying to tile your bathroom floor. You are allowed to pick only one shape and size of tile. The tile has to be a regular polygon (meaning all the same

More information

CSC 221: Computer Programming I. Fall 2011

CSC 221: Computer Programming I. Fall 2011 CSC 221: Computer Programming I Fall 2011 Python control statements operator precedence importing modules random, math conditional execution: if, if-else, if-elif-else counter-driven repetition: for conditional

More information

MATHEMATICS Y3 Using and applying mathematics 3810 Solve mathematical puzzles and investigate. Equipment MathSphere www.mathsphere.co.

MATHEMATICS Y3 Using and applying mathematics 3810 Solve mathematical puzzles and investigate. Equipment MathSphere www.mathsphere.co. MATHEMATICS Y3 Using and applying mathematics 3810 Solve mathematical puzzles and investigate. Equipment Paper, pencil, ruler Dice, number cards, buttons/counters, boxes etc MathSphere 3810 Solve mathematical

More information

STEP 0: OPEN UP THE PYTHON EDITOR. If python is on your computer already, it's time to get started. On Windows, find IDLE in the start menu.

STEP 0: OPEN UP THE PYTHON EDITOR. If python is on your computer already, it's time to get started. On Windows, find IDLE in the start menu. 01 Turtle Power Introduction: This term we're going to be learning a computer programming language called Python. The person who created Python named it after his favourite TV show: Monty Python s Flying

More information

Shapes Bingo. More general matters which apply to the use of this unit are covered on the next page.

Shapes Bingo. More general matters which apply to the use of this unit are covered on the next page. Shapes Bingo Shapes Bingo This unit provides the material for practicing some basic shape identification in the context of the well-known game of Bingo. Directions on how to play Bingo are not given here.

More information

MSW LOGO 2. MSW LOGO is a programming language that lets you store a series of instructions on the computer.

MSW LOGO 2. MSW LOGO is a programming language that lets you store a series of instructions on the computer. MSW LOGO 2 MSW LOGO is a programming language that lets you store a series of instructions on the computer. You can write routines based on the commands you have learnt earlier (refer to MS Logo 1). 1

More information

GAP CLOSING. 2D Measurement. Intermediate / Senior Student Book

GAP CLOSING. 2D Measurement. Intermediate / Senior Student Book GAP CLOSING 2D Measurement Intermediate / Senior Student Book 2-D Measurement Diagnostic...3 Areas of Parallelograms, Triangles, and Trapezoids...6 Areas of Composite Shapes...14 Circumferences and Areas

More information

Python. KS3 Programming Workbook. Name. ICT Teacher Form. Do you speak Parseltongue?

Python. KS3 Programming Workbook. Name. ICT Teacher Form. Do you speak Parseltongue? Python KS3 Programming Workbook Do you speak Parseltongue? Name ICT Teacher Form Welcome to Python The python software has two windows that we will use. The main window is called the Python Shell and allows

More information

CS177 MIDTERM 2 PRACTICE EXAM SOLUTION. Name: Student ID:

CS177 MIDTERM 2 PRACTICE EXAM SOLUTION. Name: Student ID: CS177 MIDTERM 2 PRACTICE EXAM SOLUTION Name: Student ID: This practice exam is due the day of the midterm 2 exam. The solutions will be posted the day before the exam but we encourage you to look at the

More information

Welcome to Introduction to programming in Python

Welcome to Introduction to programming in Python Welcome to Introduction to programming in Python Suffolk One, Ipswich, 4:30 to 6:00 Tuesday Jan 14, Jan 21, Jan 28, Feb 11 Welcome Fire exits Toilets Refreshments 1 Learning objectives of the course An

More information

Introduction to Python

Introduction to Python WEEK ONE Introduction to Python Python is such a simple language to learn that we can throw away the manual and start with an example. Traditionally, the first program to write in any programming language

More information

Python for Rookies. Example Examination Paper

Python for Rookies. Example Examination Paper Python for Rookies Example Examination Paper Instructions to Students: Time Allowed: 2 hours. This is Open Book Examination. All questions carry 25 marks. There are 5 questions in this exam. You should

More information

Target To know the properties of a rectangle

Target To know the properties of a rectangle Target To know the properties of a rectangle (1) A rectangle is a 3-D shape. (2) A rectangle is the same as an oblong. (3) A rectangle is a quadrilateral. (4) Rectangles have four equal sides. (5) Rectangles

More information

Python Lists and Loops

Python Lists and Loops WEEK THREE Python Lists and Loops You ve made it to Week 3, well done! Most programs need to keep track of a list (or collection) of things (e.g. names) at one time or another, and this week we ll show

More information

Chapter 2 Writing Simple Programs

Chapter 2 Writing Simple Programs Chapter 2 Writing Simple Programs Charles Severance Textbook: Python Programming: An Introduction to Computer Science, John Zelle Software Development Process Figure out the problem - for simple problems

More information

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition Objectives In this chapter, you will learn about: Representing algorithms Examples of algorithmic problem

More information

UNIT H1 Angles and Symmetry Activities

UNIT H1 Angles and Symmetry Activities UNIT H1 Angles and Symmetry Activities Activities H1.1 Lines of Symmetry H1.2 Rotational and Line Symmetry H1.3 Symmetry of Regular Polygons H1.4 Interior Angles in Polygons Notes and Solutions (1 page)

More information

Introduction to Computer Science I Spring 2014 Mid-term exam Solutions

Introduction to Computer Science I Spring 2014 Mid-term exam Solutions Introduction to Computer Science I Spring 2014 Mid-term exam Solutions 1. Question: Consider the following module of Python code... def thing_one (x): y = 0 if x == 1: y = x x = 2 if x == 2: y = -x x =

More information

Exercise 1: Python Language Basics

Exercise 1: Python Language Basics Exercise 1: Python Language Basics In this exercise we will cover the basic principles of the Python language. All languages have a standard set of functionality including the ability to comment code,

More information

Year 9 mathematics test

Year 9 mathematics test Ma KEY STAGE 3 Year 9 mathematics test Tier 6 8 Paper 1 Calculator not allowed First name Last name Class Date Please read this page, but do not open your booklet until your teacher tells you to start.

More information

Introduction to Computers and Programming. Testing

Introduction to Computers and Programming. Testing Introduction to Computers and Programming Prof. I. K. Lundqvist Lecture 13 April 16 2004 Testing Goals of Testing Classification Test Coverage Test Technique Blackbox vs Whitebox Real bugs and software

More information

Paper 1. Calculator not allowed. Mathematics test. First name. Last name. School. Remember KEY STAGE 3 TIER 5 7

Paper 1. Calculator not allowed. Mathematics test. First name. Last name. School. Remember KEY STAGE 3 TIER 5 7 Ma KEY STAGE 3 Mathematics test TIER 5 7 Paper 1 Calculator not allowed First name Last name School 2009 Remember The test is 1 hour long. You must not use a calculator for any question in this test. You

More information

Grade 4 Mathematics Patterns, Relations, and Functions: Lesson 1

Grade 4 Mathematics Patterns, Relations, and Functions: Lesson 1 Grade 4 Mathematics Patterns, Relations, and Functions: Lesson 1 Read aloud to the students the material that is printed in boldface type inside the boxes. Information in regular type inside the boxes

More information

Geometry of 2D Shapes

Geometry of 2D Shapes Name: Geometry of 2D Shapes Answer these questions in your class workbook: 1. Give the definitions of each of the following shapes and draw an example of each one: a) equilateral triangle b) isosceles

More information

The Richard Pate School. Draft Year 4 Scheme of Work for Scratch

The Richard Pate School. Draft Year 4 Scheme of Work for Scratch The Richard Pate School Draft Year 4 Scheme of Work for Scratch Marcus Gilvear July 2014 (Acknowledgements: Phil Bagge and Duncan Hooper) Re Scratch: This work is licensed under the Creative Commons Attribution-NonCommercial

More information

Pseudo code Tutorial and Exercises Teacher s Version

Pseudo code Tutorial and Exercises Teacher s Version Pseudo code Tutorial and Exercises Teacher s Version Pseudo-code is an informal way to express the design of a computer program or an algorithm in 1.45. The aim is to get the idea quickly and also easy

More information

PYTHON Basics http://hetland.org/writing/instant-hacking.html

PYTHON Basics http://hetland.org/writing/instant-hacking.html CWCS Workshop May 2009 PYTHON Basics http://hetland.org/writing/instant-hacking.html Python is an easy to learn, modern, interpreted, object-oriented programming language. It was designed to be as simple

More information

1. a procedure that you perform frequently. 2. Create a command. 3. Create a new. 4. Create custom for Excel.

1. a procedure that you perform frequently. 2. Create a command. 3. Create a new. 4. Create custom for Excel. Topics 1 Visual Basic Application Macro Language What You Can Do with VBA macro Types of VBA macro Recording VBA macros Example: MyName () If-Then statement Example: CheckCell () For-Next Loops Example:

More information

Crash Dive into Python

Crash Dive into Python ECPE 170 University of the Pacific Crash Dive into Python 2 Lab Schedule Ac:vi:es Assignments Due Today Lab 11 Network Programming Due by Dec 1 st 5:00am Python Lab 12 Next Week Due by Dec 8 th 5:00am

More information

Python Loops and String Manipulation

Python Loops and String Manipulation WEEK TWO Python Loops and String Manipulation Last week, we showed you some basic Python programming and gave you some intriguing problems to solve. But it is hard to do anything really exciting until

More information

Crash Dive into Python

Crash Dive into Python ECPE 170 University of the Pacific Crash Dive into Python 2 Lab Schedule Ac:vi:es Assignments Due Today Lab 8 Python Due by Oct 26 th 5:00am Endianness Lab 9 Tuesday Due by Nov 2 nd 5:00am Network programming

More information

Grade 3 Core Standard III Assessment

Grade 3 Core Standard III Assessment Grade 3 Core Standard III Assessment Geometry and Measurement Name: Date: 3.3.1 Identify right angles in two-dimensional shapes and determine if angles are greater than or less than a right angle (obtuse

More information

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements 9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending

More information

Data Flow Diagrams. Outline. Some Rules for External Entities 1/25/2010. Mechanics

Data Flow Diagrams. Outline. Some Rules for External Entities 1/25/2010. Mechanics Data Flow Diagrams Mechanics Outline DFD symbols External entities (sources and sinks) Data Stores Data Flows Processes Types of diagrams Step by step approach Rules Some Rules for External Entities External

More information

Visual Logic Instructions and Assignments

Visual Logic Instructions and Assignments Visual Logic Instructions and Assignments Visual Logic can be installed from the CD that accompanies our textbook. It is a nifty tool for creating program flowcharts, but that is only half of the story.

More information

CBA Fractions Student Sheet 1

CBA Fractions Student Sheet 1 Student Sheet 1 1. If 3 people share 12 cookies equally, how many cookies does each person get? 2. Four people want to share 5 cakes equally. Show how much each person gets. Student Sheet 2 1. The candy

More information

Paper Reference. Edexcel GCSE Mathematics (Linear) 1380 Paper 1 (Non-Calculator) Foundation Tier

Paper Reference. Edexcel GCSE Mathematics (Linear) 1380 Paper 1 (Non-Calculator) Foundation Tier Centre No. Candidate No. Paper Reference 1 3 8 0 1 F Paper Reference(s) 1380/1F Edexcel GCSE Mathematics (Linear) 1380 Paper 1 (Non-Calculator) Foundation Tier Friday 2 March 2012 Afternoon Time: 1 hour

More information

Programming in Access VBA

Programming in Access VBA PART I Programming in Access VBA In this part, you will learn all about how Visual Basic for Applications (VBA) works for Access 2010. A number of new VBA features have been incorporated into the 2010

More information

Exercise 4 Learning Python language fundamentals

Exercise 4 Learning Python language fundamentals Exercise 4 Learning Python language fundamentals Work with numbers Python can be used as a powerful calculator. Practicing math calculations in Python will help you not only perform these tasks, but also

More information

Which two rectangles fit together, without overlapping, to make a square?

Which two rectangles fit together, without overlapping, to make a square? SHAPE level 4 questions 1. Here are six rectangles on a grid. A B C D E F Which two rectangles fit together, without overlapping, to make a square?... and... International School of Madrid 1 2. Emily has

More information

Test Case Design Techniques

Test Case Design Techniques Summary of Test Case Design Techniques Brian Nielsen, Arne Skou {bnielsen ask}@cs.auc.dk Development of Test Cases Complete testing is impossible Testing cannot guarantee the absence of faults How to select

More information

GAP CLOSING. 2D Measurement GAP CLOSING. Intermeditate / Senior Facilitator s Guide. 2D Measurement

GAP CLOSING. 2D Measurement GAP CLOSING. Intermeditate / Senior Facilitator s Guide. 2D Measurement GAP CLOSING 2D Measurement GAP CLOSING 2D Measurement Intermeditate / Senior Facilitator s Guide 2-D Measurement Diagnostic...4 Administer the diagnostic...4 Using diagnostic results to personalize interventions...4

More information

2. How many ways can the letters in PHOENIX be rearranged? 7! = 5,040 ways.

2. How many ways can the letters in PHOENIX be rearranged? 7! = 5,040 ways. Math 142 September 27, 2011 1. How many ways can 9 people be arranged in order? 9! = 362,880 ways 2. How many ways can the letters in PHOENIX be rearranged? 7! = 5,040 ways. 3. The letters in MATH are

More information

Paper 1. Calculator not allowed. Mathematics test. First name. Last name. School. Remember KEY STAGE 3 TIER 4 6

Paper 1. Calculator not allowed. Mathematics test. First name. Last name. School. Remember KEY STAGE 3 TIER 4 6 Ma KEY STAGE 3 Mathematics test TIER 4 6 Paper 1 Calculator not allowed First name Last name School 2007 Remember The test is 1 hour long. You must not use a calculator for any question in this test. You

More information

Lecture 2 Notes: Flow of Control

Lecture 2 Notes: Flow of Control 6.096 Introduction to C++ January, 2011 Massachusetts Institute of Technology John Marrero Lecture 2 Notes: Flow of Control 1 Motivation Normally, a program executes statements from first to last. The

More information

Excel for Mac Text Functions

Excel for Mac Text Functions [Type here] Excel for Mac Text Functions HOW TO CLEAN UP TEXT IN A FLASH This document looks at some of the tools available in Excel 2008 and Excel 2011 for manipulating text. Last updated 16 th July 2015

More information

Computer Science for San Francisco Youth

Computer Science for San Francisco Youth Python for Beginners Python for Beginners Lesson 0. A Short Intro Lesson 1. My First Python Program Lesson 2. Input from user Lesson 3. Variables Lesson 4. If Statements How If Statements Work Structure

More information

Colour by Numbers Image Representation

Colour by Numbers Image Representation Activity 2 Colour by Numbers Image Representation Summary Computers store drawings, photographs and other pictures using only numbers. The following activity demonstrates how they can do this. Curriculum

More information

Python 3 Programming. OCR GCSE Computing

Python 3 Programming. OCR GCSE Computing Python 3 Programming OCR GCSE Computing OCR 2012 1 Contents Introduction 3 1. Output to the screen 5 2. Storing Data in Variables 6 3. Inputting Data 8 4. Calculations 9 5. Data Types 10 6. Selection with

More information

6. Control Structures

6. Control Structures - 35 - Control Structures: 6. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose,

More information

Chapter 9: Building Bigger Programs

Chapter 9: Building Bigger Programs Chapter 9: Building Bigger Programs How to Design Larger Programs Building something larger requires good software engineering. Design Top- down: Start from requirements, then identify the pieces to write,

More information

Numeracy Targets. I can count at least 20 objects

Numeracy Targets. I can count at least 20 objects Targets 1c I can read numbers up to 10 I can count up to 10 objects I can say the number names in order up to 20 I can write at least 4 numbers up to 10. When someone gives me a small number of objects

More information

River Dell Regional School District. Computer Programming with Python Curriculum

River Dell Regional School District. Computer Programming with Python Curriculum River Dell Regional School District Computer Programming with Python Curriculum 2015 Mr. Patrick Fletcher Superintendent River Dell Regional Schools Ms. Lorraine Brooks Principal River Dell High School

More information

Reasoning and Proof Review Questions

Reasoning and Proof Review Questions www.ck12.org 1 Reasoning and Proof Review Questions Inductive Reasoning from Patterns 1. What is the next term in the pattern: 1, 4, 9, 16, 25, 36, 49...? (a) 81 (b) 64 (c) 121 (d) 56 2. What is the next

More information

Chapter 5 Programming Statements. Chapter Table of Contents

Chapter 5 Programming Statements. Chapter Table of Contents Chapter 5 Programming Statements Chapter Table of Contents OVERVIEW... 57 IF-THEN/ELSE STATEMENTS... 57 DO GROUPS... 58 IterativeExecution... 59 JUMPING... 61 MODULES... 62 Defining and Executing a Module....

More information

Logistics. Software Testing. Logistics. Logistics. Plan for this week. Before we begin. Project. Final exam. Questions?

Logistics. Software Testing. Logistics. Logistics. Plan for this week. Before we begin. Project. Final exam. Questions? Logistics Project Part 3 (block) due Sunday, Oct 30 Feedback by Monday Logistics Project Part 4 (clock variant) due Sunday, Nov 13 th Individual submission Recommended: Submit by Nov 6 th Scoring Functionality

More information

Mathematical Induction

Mathematical Induction Mathematical Induction In logic, we often want to prove that every member of an infinite set has some feature. E.g., we would like to show: N 1 : is a number 1 : has the feature Φ ( x)(n 1 x! 1 x) How

More information

11.3 Curves, Polygons and Symmetry

11.3 Curves, Polygons and Symmetry 11.3 Curves, Polygons and Symmetry Polygons Simple Definition A shape is simple if it doesn t cross itself, except maybe at the endpoints. Closed Definition A shape is closed if the endpoints meet. Polygon

More information

An Introduction to Number Theory Prime Numbers and Their Applications.

An Introduction to Number Theory Prime Numbers and Their Applications. East Tennessee State University Digital Commons @ East Tennessee State University Electronic Theses and Dissertations 8-2006 An Introduction to Number Theory Prime Numbers and Their Applications. Crystal

More information

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University http://www.cs.stonybrook.

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University http://www.cs.stonybrook. Elementary Number Theory and Methods of Proof CSE 215, Foundations of Computer Science Stony Brook University http://www.cs.stonybrook.edu/~cse215 1 Number theory Properties: 2 Properties of integers (whole

More information

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June 2014. Dr.-Ing.

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June 2014. Dr.-Ing. Computers An Introduction to Programming with Python CCHSG Visit June 2014 Dr.-Ing. Norbert Völker Many computing devices are embedded Can you think of computers/ computing devices you may have in your

More information

2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION

2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION 2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION A world-coordinate area selected for display is called a window. An area on a display device to which a window is mapped is called a viewport. The window

More information

Computer Science 217

Computer Science 217 Computer Science 217 Midterm Exam Fall 2009 October 29, 2009 Name: ID: Instructions: Neatly print your name and ID number in the spaces provided above. Pick the best answer for each multiple choice question.

More information

Python Evaluation Rules

Python Evaluation Rules Python Evaluation Rules UW CSE 160 http://tinyurl.com/dataprogramming Michael Ernst and Isaac Reynolds [email protected] August 2, 2016 Contents 1 Introduction 2 1.1 The Structure of a Python Program................................

More information

Grade 3 FCAT 2.0 Mathematics Sample Answers

Grade 3 FCAT 2.0 Mathematics Sample Answers Grade FCAT 2.0 Mathematics Sample Answers This booklet contains the answers to the FCAT 2.0 Mathematics sample questions, as well as explanations for the answers. It also gives the Next Generation Sunshine

More information

FIRST GRADE MATH Summer 2011

FIRST GRADE MATH Summer 2011 Standards Summer 2011 1 OA.1 Use addition and subtraction within 20 to solve word problems involving situations of adding to, taking from, putting together, taking apart, and comparing, with unknowns in

More information

Symbol Tables. Introduction

Symbol Tables. Introduction Symbol Tables Introduction A compiler needs to collect and use information about the names appearing in the source program. This information is entered into a data structure called a symbol table. The

More information

Fractions as Parts of a Group

Fractions as Parts of a Group 1 Fractions as Parts of a Group Use fractions to describe parts of a group. 1. 5 of the squares are white. a) What fraction of the group are people? b) What fraction of the group are dogs? 8 or 1 2 8 is

More information

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A Developed By Brian Weinfeld Course Description: AP Computer

More information

Software Testing, Mythology & Methodologies

Software Testing, Mythology & Methodologies Software, Mythology & Methodologies Sonali Waje 1, Vandana Gaikwad 2, Pranchal Chaudhari 3 1,3 B.E. Information Technology, 2 B.E.Computer Engineering Abstract - It is generally believed that phases of

More information

Test case design techniques I: Whitebox testing CISS

Test case design techniques I: Whitebox testing CISS Test case design techniques I: Whitebox testing Overview What is a test case Sources for test case derivation Test case execution White box testing Flowgraphs Test criteria/coverage Statement / branch

More information

Monday 11 June 2012 Afternoon

Monday 11 June 2012 Afternoon THIS IS A NEW SPECIFICATION F Monday 11 June 2012 Afternoon GCSE MATHEMATICS B J567/01 Paper 1 (Foundation Tier) *J517110612* Candidates answer on the Question Paper. OCR supplied materials: None Other

More information

The three tests of mental ability you will be asked to do at the AOSB are:

The three tests of mental ability you will be asked to do at the AOSB are: Introduction The Army requires that candidates for Officer Training have certain mental abilities. These mental abilities are measured by three tests that are described in this booklet. It is essential

More information

Shape Dictionary YR to Y6

Shape Dictionary YR to Y6 Shape Dictionary YR to Y6 Guidance Notes The terms in this dictionary are taken from the booklet Mathematical Vocabulary produced by the National Numeracy Strategy. Children need to understand and use

More information

Estimating Angle Measures

Estimating Angle Measures 1 Estimating Angle Measures Compare and estimate angle measures. You will need a protractor. 1. Estimate the size of each angle. a) c) You can estimate the size of an angle by comparing it to an angle

More information

DISCOVERING 3D SHAPES

DISCOVERING 3D SHAPES . DISCOVERING 3D SHAPES WORKSHEETS OCTOBER-DECEMBER 2009 1 . Worksheet 1. Cut out and stick the shapes. SHAPES WHICH ROLL SHAPES WHICH SLIDE 2 . Worksheet 2: COMPLETE THE CHARTS Sphere, triangle, prism,

More information

Goal: Practice writing pseudocode and understand how pseudocode translates to real code.

Goal: Practice writing pseudocode and understand how pseudocode translates to real code. Lab 7: Pseudocode Pseudocode is code written for human understanding not a compiler. You can think of pseudocode as English code that can be understood by anyone (not just a computer scientist). Pseudocode

More information

Grade 7/8 Math Circles November 3/4, 2015. M.C. Escher and Tessellations

Grade 7/8 Math Circles November 3/4, 2015. M.C. Escher and Tessellations Faculty of Mathematics Waterloo, Ontario N2L 3G1 Centre for Education in Mathematics and Computing Tiling the Plane Grade 7/8 Math Circles November 3/4, 2015 M.C. Escher and Tessellations Do the following

More information

Instructions. Information. Advice

Instructions. Information. Advice Instructions Use black ink or ball-point pen. Fill in the boxes at the top of this page with your name, centre number and candidate number. Answer all questions. Answer the questions in the spaces provided

More information

Triangulation by Ear Clipping

Triangulation by Ear Clipping Triangulation by Ear Clipping David Eberly Geometric Tools, LLC http://www.geometrictools.com/ Copyright c 1998-2016. All Rights Reserved. Created: November 18, 2002 Last Modified: August 16, 2015 Contents

More information

Writing Control Structures

Writing Control Structures Writing Control Structures Copyright 2006, Oracle. All rights reserved. Oracle Database 10g: PL/SQL Fundamentals 5-1 Objectives After completing this lesson, you should be able to do the following: Identify

More information

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser) High-Level Programming Languages Nell Dale & John Lewis (adaptation by Michael Goldwasser) Low-Level Languages What are disadvantages of low-level languages? (e.g., machine code or assembly code) Programming

More information

Self-review 9.3 What is PyUnit? PyUnit is the unit testing framework that comes as standard issue with the Python system.

Self-review 9.3 What is PyUnit? PyUnit is the unit testing framework that comes as standard issue with the Python system. Testing, Testing 9 Self-Review Questions Self-review 9.1 What is unit testing? It is testing the functions, classes and methods of our applications in order to ascertain whether there are bugs in the code.

More information

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output CSCE 110 Programming Basics of Python: Variables, Expressions, and nput/output Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Fall 2011 Python Python was developed

More information

Year 9 mathematics test

Year 9 mathematics test Ma KEY STAGE 3 Year 9 mathematics test Tier 5 7 Paper 1 Calculator not allowed First name Last name Class Date Please read this page, but do not open your booklet until your teacher tells you to start.

More information

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall-2015 1

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall-2015 1 QUIZ-II Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the numbers, the operator, and the result. (For

More information

Test case design techniques I: Whitebox testing CISS

Test case design techniques I: Whitebox testing CISS Test case design techniques I: Whitebox testing Overview What is a test case Sources for test case derivation Test case execution White box testing Flowgraphs Test criteria/coverage Statement / branch

More information

Test Design Strategies

Test Design Strategies Test Design Strategies Louise Tamres, CSQE ASQ Software Division Webinar 18 July 2008 1 Objectives Translate requirements into test cases Improve communication by producing models Identify incomplete requirements

More information

2 SYSTEM DESCRIPTION TECHNIQUES

2 SYSTEM DESCRIPTION TECHNIQUES 2 SYSTEM DESCRIPTION TECHNIQUES 2.1 INTRODUCTION Graphical representation of any process is always better and more meaningful than its representation in words. Moreover, it is very difficult to arrange

More information

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python Introduction Welcome to our Python sessions. University of Hull Department of Computer Science Wrestling with Python Week 01 Playing with Python Vsn. 1.0 Rob Miles 2013 Please follow the instructions carefully.

More information

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share. LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.

More information

Sudoku puzzles and how to solve them

Sudoku puzzles and how to solve them Sudoku puzzles and how to solve them Andries E. Brouwer 2006-05-31 1 Sudoku Figure 1: Two puzzles the second one is difficult A Sudoku puzzle (of classical type ) consists of a 9-by-9 matrix partitioned

More information

Software Testing. Quality & Testing. Software Testing

Software Testing. Quality & Testing. Software Testing Software Testing Software Testing Error: mistake made by the programmer/developer Fault: a incorrect piece of code/document (i.e., bug) Failure: result of a fault Goal of software testing: Cause failures

More information

PGR Computing Programming Skills

PGR Computing Programming Skills PGR Computing Programming Skills Dr. I. Hawke 2008 1 Introduction The purpose of computing is to do something faster, more efficiently and more reliably than you could as a human do it. One obvious point

More information

Mathematics A *P44587A0128* Pearson Edexcel GCSE P44587A. Paper 2 (Calculator) Higher Tier. Friday 7 November 2014 Morning Time: 1 hour 45 minutes

Mathematics A *P44587A0128* Pearson Edexcel GCSE P44587A. Paper 2 (Calculator) Higher Tier. Friday 7 November 2014 Morning Time: 1 hour 45 minutes Write your name here Surname Other names Pearson Edexcel GCSE Centre Number Mathematics A Paper 2 (Calculator) Friday 7 November 2014 Morning Time: 1 hour 45 minutes Candidate Number Higher Tier Paper

More information

Outline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators

Outline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators Conditional Statements For computer to make decisions, must be able to test CONDITIONS IF it is raining THEN I will not go outside IF Count is not zero THEN the Average is Sum divided by Count Conditions

More information