Overview Program flow Decision / branching / selection structures True & False in Python Comparison operators & Boolean expressions if … if … else if …

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

Chapter 2 Flow of Control. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 2-2 Learning Objectives Boolean Expressions Building, Evaluating.
Control Flow Statements: Repetition/Looping
CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
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.
Python Programming Language
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
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.
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
Basic Elements of Programming A VB program is built from statements, statements from expressions, expressions from operators and operands, and operands.
Conditions What if?. Flow of Control The order of statement execution is called the flow of control Unless specified otherwise, the order of statement.
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Decision Making George Mason University. Today’s topics 2 Review of Chapter 2: Decision Making Go over exercises Decision making in Python.
Geography 465 Assignments, Conditionals, and Loops.
Python Control of Flow.
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
Branching and Conditions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
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.
Computer Science Selection Structures.
Chapter 3 Making Decisions
Object-Oriented Programming Using C++ Third Edition Chapter 3 Making Decisions.
Visual C# 2005 Decision Structures. Visual C# Objectives Understand decision making Learn how to make decisions using the if statement Learn how.
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.
1 Boolean Expressions to Make Comparisons Boolean expression –Represents only one of two states –Expression evaluates to either true or false Expressions.
Decision Making CMSC 201. Overview Today we will learn about: Boolean expressions Decision making.
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.
Flow of Control Unless indicated otherwise, the order of statement execution through a method is linear: one after the other in the order they are written.
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.
Visual Basic CDA College Limassol Campus COM123 Visual Basic Programming Semester C Lecture:Pelekanou Olga Week 4: Understand and implement Decisions.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Decision Making CMSC 201 Chang (rev ).
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.
C++ Programming Lecture 5 Control Structure I (Selection) – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook.
Python Basics  Values, Types, Variables, Expressions  Assignments  I/O  Control Structures.
Pascal Programming George Boole, a 19 th Century mathematician, is created with true, false logic. A Boolean expression in Pascal will be true or false.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
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.
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
 Type Called bool  Bool has only two possible values: True and False.
Control Flow (Python) Dr. José M. Reyes Álamo.
Upsorn Praphamontripong CS 1110 Introduction to Programming Fall 2016
Chapter 3 Branching Statements
Topics The if Statement The if-else Statement Comparing Strings
Expressions and Control Flow in JavaScript
Topics The if Statement The if-else Statement Comparing Strings
Selection CIS 40 – Introduction to Programming in Python
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
Program Flow Control Selection & repetition
Chapter 8: More on the Repetition Structure
Visual Basic – Decision Statements
Comparing Strings Strings can be compared using the == and != operators String comparisons are case sensitive Strings can be compared using >, =, and.
CS 1111 Introduction to Programming Spring 2019
Topics The if Statement The if-else Statement Comparing Strings
Types, Truth, and Expressions (Part 2)
Winter 2019 CISC101 4/16/2019 CISC101 Reminders
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
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.
LOOP Basics.
Presentation transcript:

Overview Program flow Decision / branching / selection structures True & False in Python Comparison operators & Boolean expressions if … if … else if … elif … else

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 valuesFalse Values Non-zero numbers (positive & negative) 0 Non-empty stringEmpty string Non-empty listEmpty list Non-empty tupleEmpty tuple Non-empty dictionaryEmpty dictionary not None None TrueFalse

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

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

Overview Program flow Decision / branching / selection structures True & False in Python Comparison operators & Boolean expressions if … if … else if … elif … else