Selection Victor Norman CS104 Calvin College. Reading Quiz Counts toward your grade.

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

Copyright © 2003 Pearson Education, Inc. Slide 1.
Chapter 4 - Control Statements
Chapter 4 Decision Making Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E. Reingold.
Selection in Python If statements.
Conditional Execution
Python Programming Language
Overview Program flow Decision / branching / selection structures True & False in Python Comparison operators & Boolean expressions if … if … else if …
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
1 CS 105 Lecture 4 Selection Statements Wed, Jan 26, 2011, 6:05 pm.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
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,
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
Geography 465 Assignments, Conditionals, and Loops.
Q and A for Section 4.4 CS 106, Fall Q1 Q: The syntax for an if statement (or conditional statement) is: if _______________ : _____________ A: if.
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.
Announcements 1st homework is due on July 16, next Wednesday, at 19:00 Submit to SUCourse About the homework: Add the following at the end of your code.
Chapter 8 Conditionals. Learning Java through Alice © Daly and Wrigley Objectives List relational operators. List logical operators. Use the hierarchy.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
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.
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
Computer Science 111 Fundamentals of Programming I Making Choices with if Statements.
MS3304: Week 6 Conditional statements. Overview The flow of control through a script Boolean Logic Conditional & logical operators Basic decision making.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
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.
Decision Structures, String Comparison, Nested Structures
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
CONDITIONALS. Boolean values Boolean value is either true or false It is name after the British mathemetician, George Boole who first formulated Boolean.
An Object-Oriented Approach to Programming Logic and Design Chapter 5 Making Decisions.
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.
Student Q and As from 5.1 – 5.7, 5.11 Students of CS104, Fall 2013 (and me)
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.
Chapter 6 Conditionals. Learning Java through Alice © Daly and Wrigley Objectives List relational operators. List logical operators. Use the hierarchy.
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)
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
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.
Silberschatz and Galvin  C Programming Language Decision making in C Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University.
Chapter 7 Conditional Statements. 7.1 Conditional Expressions Condition – any expression that evaluates to true/false value Relational operators are BINARY.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
Q and A for Section 4.4 CS 106, Fall If statement syntax Q: The syntax for an if statement (or conditional statement) is: if _______________ : _____________.
 Type Called bool  Bool has only two possible values: True and False.
Control Flow (Python) Dr. José M. Reyes Álamo.
Making Choices with if Statements
Sequence, Selection, Iteration The IF Statement
Chapter 6 Conditionals.
Topics The if Statement The if-else Statement Comparing Strings
JavaScript conditional
Topics The if Statement The if-else Statement Comparing Strings
Quiz 1 96/07/23.
Visual Basic – Decision Statements
Introduction To Robot Decision Making
Adding Intelligence Check for the presence or absence of a condition in the environment Take the appropriate actions Involves making a choice (to do or.
JavaScript conditional
Nate Brunelle Today: Conditional Decision Statements
Chapter 5 Decisions.
Winter 2019 CISC101 4/16/2019 CISC101 Reminders
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
CHAPTER 5: Control Flow Tools (if statement)
Conditionals.
Chapter 6 Conditionals.
Presentation transcript:

Selection Victor Norman CS104 Calvin College

Reading Quiz Counts toward your grade.

New type: bool Stands for Boolean (named after George Boole) Two values: True and False Operations: –and, or, not – equality ( == ), inequality ( != )

Booleans necessary for “testing” You “constantly” are making decision: – if something is true, I’ll do this, otherwise, I’ll do that. – Code is similar. if something < somethingelse: – something < somethingelse is a boolean expression: produces True or False. if something == 0: – True if something evaluates to the value 0, False otherwise. Can be used in assignments: – witch = (she == duck) # witch has value True or False.

Boolean operators > etc:, =, ==, != Logical Operators: and or not

Clicker Questions

if Statement Syntax if : if : else:

Chained Conditionals if : elif : elif : else: # optional!

Example of use Suppose you have a function called turnDegrees(deg) which takes a positive or negative value in deg. You want to turnLeft() if deg is positive, turnRight() if negative, and do nothing if 0. How would you write this code? if deg > 0: # this code in turnDegrees() turnLeft(deg) elif deg < 0: turnRight(-1 * deg)

Nested conditional Q: Write code that prints the word “odd” or “even” depending on the value of variable anInt, and also prints “greater than 10” if the odd number has a value greater than 10. A: if anInt % 2 == 0 : print "even” else: print "odd” if anInt > 10: print "greater than 10”

Clicker Question if temperature > 0: print("above freezing") elif temperature == 0: print("at freezing") else: print("below freezing") Does the code below do exactly the same thing as the code above? (Assume temperature already refers to some numeric value.) if temperature > 0: print("above freezing") elif temperature == 0: print("at freezing") elif temperature < 0: print("below freezing")

Clicker Question age | experience: 0 | 1-2 | under 18 | $6.50 | $9.50 | $ and over | $6.50 | $12.00 | $12.00 if experience == 0: wage = 6.5 elif (1) : if (2) : wage = 9.5 else: wage = 11 else: wage = 12

Assignment Do ~60 questions in CodeLab. Very good practice!