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.

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

If Statements, Try Catch and Validation. The main statement used in C# for making decisions depending on different conditions is called the If statement.
Lecture 3: Control Structures - Selection BJ Furman 10SEP2012.
MONTEGO BAY HIGH SCHOOL INFORMATION TECHNOLOGY THE EXCEL IF FUNCTION.
Making Decisions in Python Sec 9-10 Web Design. Objectives The student will: Understand how to make a decision in Python Understand the structure of an.
Python Programming Language
Conditional Statements Introduction to Computing Science and Programming I.
Overview Program flow Decision / branching / selection structures True & False in Python Comparison operators & Boolean expressions if … if … else if …
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
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,
Geography 465 Assignments, Conditionals, and Loops.
INTRODUCTION TO PYTHON PART 3 - LOOPS AND CONDITIONAL LOGIC CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
Python Control of Flow.
Chapter 9 IF Statement Bernard Chen. If Statement The main statement used for selecting from alternative actions based on test results It’s the primary.
Chapter 9 IF Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 4 Decision Structures and Boolean Logic.
Python Programming Using Variables and input. Objectives We’re learning to make use of if statements to enable code to ask questions. Outcomes Build an.
Decision Structures and Boolean Logic
Lecture 10 – Boolean expressions, if statements COMPSCI 101 Principles of Programming.
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.
Chapter 04 Control Statements: Part II. OBJECTIVES In this part you will learn: if…else Double-Selection Statement. while Repetition Statement.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
Decision Making CMSC 201. Overview Today we will learn about: Boolean expressions Decision making.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Boolean Expressions and Logical Operators CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington Credits:
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Decision Making CMSC 201 Chang (rev ).
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 3 Decision Trees Conditionals.
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.
These Guys? Wait, What? Really?  Branching is a fundamental part of programming  It means taking an action based on decision  The decision is dependent.
If statement.  It is made up of three main components:  The keyword itself,  an expression that is tested for its truth value,  and a code suite to.
Programming Language C++ Lecture 3. Control Structures  C++ provides control structures that serve to specify what has to be done to perform our program.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
PYTHON WHILE LOOPS. What you know While something is true, repeat your action(s) Example: While you are not facing a wall, walk forward While you are.
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.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Python – Part 4 Conditionals and Recursion. Conditional execution If statement if x>0:# CONDITION print (‘x is positive’) Same structure as function definition.
Python Fundamentals: If Statements and Functions Eric Shook Department of Geography Kent State University.
Sensor Information: while loops and Boolean Logic.
 Type Called bool  Bool has only two possible values: True and False.
Control Flow (Python) Dr. José M. Reyes Álamo.
CHAPTER 4 DECISIONS & LOOPS
Selection: Non-linear programs
Making Choices with if Statements
Sequence, Selection, Iteration The IF Statement
Selection and Python Syntax
Operator Precedence Operators Precedence Parentheses () unary
Topics The if Statement The if-else Statement Comparing Strings
If, else, elif.
Topics The if Statement The if-else Statement Comparing Strings
Selection CIS 40 – Introduction to Programming in Python
Python - Conditional Execution
Selection (IF Statements)
Multiple Selections (ELIF Statements)
Introduction to Programming
Program Flow Control Selection & repetition
Visual Basic – Decision Statements
Introduction to Programming Using Python PART 2
CS 1111 Introduction to Programming Spring 2019
Topics The if Statement The if-else Statement Comparing Strings
Python Programming Language
CHAPTER 5: Control Flow Tools (if statement)
Python While Loops.
Introduction to Programming
Lecture 9: JavaScript Syntax
Presentation transcript:

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 decisions

If - Syntax if (condition): indented code block

Comparison Operators Equal to Greater than Less than Greater than or equal to Less than or equal to Not equal to == > < >= <= !=

Else- Syntax What if you want something to happen when the if condition is false?

If Else - Example

Checking for Multiple Conditions We use an elif statement to check multiple conditions.

Elif - Example

Logic Operators Check for multiple conditions in the same keyword. There are only three: and, or, not.

Precedence

You asleep yet?

Logic Example