Starter What does the following code do?

Slides:



Advertisements
Similar presentations
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
Advertisements

PSEUDOCODE & FLOW CHART
ITEC113 Algorithms and Programming Techniques
PYTHON PROGRAMMING Week 10 – Wednesday. TERMS – CHAPTER 1 Write down definitions for these terms:  Computation  Computability  Computing  Artificial.
CPSC 171 Introduction to Computer Science 3 Levels of Understanding Algorithms More Algorithm Discovery and Design.
INTRODUCTION TO ALGORITHMS PROGRAMMING. Objectives Give a definition of the term algorithm Describe the various parts of the pseudocode algorithm or algorithm.
Input, Output, and Processing
Do it now activity Last term we learnt about how data is represented in a computer and about how to identify different volumes of data. How many bits in.
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
Pseudocode Algorithms Using Sequence, Selection, and Repetition
Algorithm Discovery and Design Objectives: Interpret pseudocode Write pseudocode, using the three types of operations: * sequential (steps in order written)
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.
A Level Computing#BristolMet Session Objectives#U2 S3 MUST use/read programme flow charts accurately SHOULD adapt the calculator programme to include a.
Python Lesson 2.
Algorithms and Pseudocode
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.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Lecture 2 Debugging,
GCSE COMPUTER SCIENCE Practical Programming using Python Lesson 4 - Selection.
PYTHON PROGRAMMING Year 9. Objective and Outcome Teaching Objective Today we will look at conditional statements in order to understand how programs can.
DEVRY CIS 170 C I L AB 2 OF 7 D ECISIONS Check this A+ tutorial guideline at decisions For.
Component 1.6.
Programming – Algorithms (Flowcharts)
GCSE COMPUTER SCIENCE Practical Programming using Python
Introduction to Computing Science and Programming I
Writing algorithms Introduction to Python.
Topics Designing a Program Input, Processing, and Output
A451 Theory – 7 Programming 7A, B - Algorithms.
Introduction to Programming
Introduction to Programming and Visual Basic
2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park
CS1001 Programming Fundamentals 3(3-0) Lecture 2
Design & Technology Grade 7 Python
Think What will be the output?
Teaching design techniques to design efficient solutions to problems
2008/09/24: Lecture 6b CMSC 104, Section 0101 John Y. Park
Learning to Program in Python
Print slides for students reference
Control Structure Senior Lecturer
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Pseudocode algorithms using sequence, selection and repetition
1) C program development 2) Selection structure
Lecture Notes 8/24/04 (part 2)
If selection construct
Do While (condition is true) … Loop
Introduction to Programming
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
If selection construct
Introduction to Programming
Programming We have seen various examples of programming languages
Starter answer these questions in your book
Software Development Process
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
PYTHON: BUILDING BLOCKS Sequencing & Selection
Flowcharts and Pseudo Code
Topics Designing a Program Input, Processing, and Output
Programming Concepts and Database
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Topics Designing a Program Input, Processing, and Output
Programming In Lesson 4.
Introduction to Python
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Introduction to Programming
Introduction to Programming
WJEC GCSE Computer Science
Algorithms For use in Unit 2 Exam.
Starter Which of these inventions is: Used most by people in Britain
Python Creating a calculator.
Presentation transcript:

Starter What does the following code do? Extension: What sort of statement has been used here?

Python: Selection Statements

Objectives – 2.1.7 Candidates should be able to: (a) understand algorithms (written in pseudocode or flow diagram), explain what they do, and correct or complete them (b) produce algorithms in pseudocode or flow diagrams to solve problems. (h) understand and use selection in an algorithm (IF and CASE statements)

Algorithms Understanding how to solve the problem is important. You cannot just start coding at line 1 and hope to get a working solution straight away Algorithm is defined as: a series of steps to solve a problem (think cooking recipes) Algorithms may be written in pseudocode Pseudocode is when we write an algorithm in programming-style constructs but not in an actual programming language.

Example Input diameter If diameter <0 “Please enter a diameter greater than 0” Else circumference = 3.141*diameter Output “Circumference is ” + circumference

Activity Write an algorithm (on paper) that will solve the problem of calculating a dog’s age. You should work in pairs. The formula is: 10.5 dog years per human year for the first 2 years, then 4 dog years per human year for each year after.

Solution Print “enter dog’s age in human years” If age <= 2 dogage = age * 10.5 Else dogage = (2*10.5) + ((age-2)*4) Output age, “in dog years is ”, dogage

Python – Selection hints A=5 - Selection if a==b: - Comparison Indentation! The code that you want python to run if your test is met must be indented. if a==b: print(‘snap’)

Activity 2 Program your algorithm using Python If you need guidance look in the resources section on BHL Hint: Remember the different data types!

You are going to some form of conditional statement to create a menu for a basic text-based calculator program. The menu should be displayed as below: Please enter the number of the operation you wish to perform: Addition Subtraction Multiplication Division Exit The program should then prompt the user for two numbers before performing, and outputting, the selected operation.

Homework You need to complete you calculators Some of you may wish to make more scientific versions

Plenary What is the purpose of an algorithm? Identify the following in this section of code: Variable Selection statement Operator Casting Step-by-step instructions to solve a problem