GIS 4107 – Week 5. David Francey … working in Toronto train yards, the Yukon bush, and as a carpenter in the Eastern Townships … releases his first CD.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
ECS 15 if and random. Topic  Testing user input using if statements  Truth and falsehood in Python  Getting random numbers.
1 Chapter Five Selection and Repetition. 2 Objectives How to make decisions using the if statement How to make decisions using the if-else statement How.
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
Overview Program flow Decision / branching / selection structures True & False in Python Comparison operators & Boolean expressions if … if … else if …
James Tam Making Decisions In Python In this section of notes you will learn how to have your Pascal programs choose between alternative courses of action.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
Decision Making George Mason University. Today’s topics 2 Review of Chapter 2: Decision Making Go over exercises Decision making in Python.
Decisions in Python elif. A new keyword elif A contraction of “else if” Used to tie two if statements (or more) together into one structure Syntax – elif,
Intro to Robots Conditionals and Recursion. Intro to Robots Modulus Two integer division operators - / and %. When dividing an integer by an integer we.
EGR 2261 Unit 4 Control Structures I: Selection  Read Malik, Chapter 4.  Homework #4 and Lab #4 due next week.  Quiz next week.
Programming Logic and Design Sixth Edition
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 4 Decision Structures and Boolean Logic.
Python Control Flow statements There are three control flow statements in Python - if, for and while.
Decision Structures and Boolean Logic
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Chapter 3 Making Decisions
Object-Oriented Programming Using C++ Third Edition Chapter 3 Making Decisions.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
Visual C# 2005 Decision Structures. Visual C# Objectives Understand decision making Learn how to make decisions using the if statement Learn how.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
Chapter 4: Making Decisions. Understanding Logic-Planning Tools and Decision Making Pseudocode – A tool that helps programmers plan a program’s logic.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
Making Decisions Chapter 5.  Thus far we have created classes and performed basic mathematical operations  Consider our ComputeArea.java program to.
1 Boolean Expressions to Make Comparisons Boolean expression –Represents only one of two states –Expression evaluates to either true or false Expressions.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Selection Statements Selection Switch Conditional.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
Quiz 3 is due Friday September 18 th Lab 6 is going to be lab practical hursSept_10/exampleLabFinal/
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
Java Programming Fifth Edition Chapter 5 Making Decisions.
Chapter 5: Making Decisions. Objectives Plan decision-making logic Make decisions with the if and if…else structures Use multiple statements in if and.
Decisions in Python Boolean functions. A Boolean function This is a function which returns a bool result (True or False). The function can certainly work.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
CONTROL STRUCTURE. 2 CHAPTER OBJECTIVES  Learn about control structures.  Examine relational and logical operators.  Explore how to form and evaluate.
An Object-Oriented Approach to Programming Logic and Design Chapter 5 Making Decisions.
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
The If Statement There are no switch statements in Python. You need to use just if statements. There are no switch statements in Python. You need to use.
Shell script – part 2 CS 302. Special shell variable $0.. $9  Positional parameters or command line arguments  For example, a script myscript take 2.
Programming Language C++ Lecture 3. Control Structures  C++ provides control structures that serve to specify what has to be done to perform our program.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 5 Making Decisions.
Python Basics  Values, Types, Variables, Expressions  Assignments  I/O  Control Structures.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
CSE202: Lecture 5The Ohio State University1 Selection Structures.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Today… Operators, Cont. Operator Precedence Conditional Statement Syntax. Winter 2016CISC101 - Prof. McLeod1.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
 Type Called bool  Bool has only two possible values: True and False.
Control Flow (Python) Dr. José M. Reyes Álamo.
Control Structures I Chapter 3
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Lesson 04: Conditionals Topic: Introduction to Programming, Zybook Ch 3, P4E Ch 3. Slides on website.
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
Topics The if Statement The if-else Statement Comparing Strings
Topics The if Statement The if-else Statement Comparing Strings
Selection CIS 40 – Introduction to Programming in Python
And now for something completely different . . .
Selection Statements.
CS 1111 Introduction to Programming Spring 2019
Topics The if Statement The if-else Statement Comparing Strings
Boolean Expressions to Make Comparisons
Winter 2019 CISC101 4/16/2019 CISC101 Reminders
CHAPTER 5: Control Flow Tools (if statement)
The Selection Structure
Flow of Control Flow of control is the order in which a program performs actions. Up to this point, the order has been sequential. A branching statement.
Presentation transcript:

GIS 4107 – Week 5

David Francey … working in Toronto train yards, the Yukon bush, and as a carpenter in the Eastern Townships … releases his first CD in 1999 at the age of 42. Look for songs “Waking Hour”,Waking Hour “Broken Glass”, “Lucky Man”, “Paper Boy”, …Broken GlassLucky ManPaper Boy

Evernote can be your exocortexexocortex “As marvelous as the brain is, we can turbocharge it by providing some key support.” Check out Evernote (video)video

Overview Miscellaneous PATH and utility scripts folder Types of error: syntax, logic, run-time Decision / branching / selection structures True & False in Python Relational & Boolean operators if … if … else if … elif … else

PATH and utility scripts folder Create and use a folder (e.g. C:\utils) on your system for useful scripts and executables (bat, py, exe, etc.) Video

Types of error Syntax Not obeying the rules of the language e.g. Not putting “:” at end of function header line Run-time Program failure while it runs. e.g. Unexpected input (string instead of number) Logic / Semantic Programmer makes mistake in coding that produces unexpected results. e.g. Invalid branching statement

Program flow overview Programs in any language have three types of flow Sequential Decision/Branching/Selection Repetition Combined in two ways Stacking Nesting Next week

Sequential - stacked

Decision / Branching / Selection Branching depends on a conditional expression Conditional expressions must evaluate to True or False How does the programming language represent True or False? How does the language make comparisons?

True & False in Python True and False are also True and False values True valuesFalse Values Non-zero numbers (postive & negative) 0 Non-empty stringEmpty string Non-empty listEmpty list Non-empty tupleEmpty tuple Non-empty dictionaryEmpty dictionary not None Null object (None)

Comparison operators & Boolean expressions With earlier versions of Python: True = 1 False = 0 Relational operators in Gaddis

if … If true, do. If not true (false), do not do. if …is a single-alternative decision structure Syntax: Indented statements!

True or False …

if … else if … else is a dual-alternative decision structure UML Activity Diagram If true, do. If not true (false), do something else.

if … elif … else Syntax: if … elif … else is a multi-alternative decision structure

Nested if Only execute the “nested if” when the “parent if” is true

Logical operators: and or not Short-circuit evaluation For “and”, if left side is False, right side is not evaluated. For “or”, if left side is True, right side is not evaluated.

Order of evaluation (precedence)

String comparisons Python uses ASCII codes to determine character values that are used in Boolean expressions.

Boolean expression as a value Same result as above if … else

We’re done