Nate Brunelle Today: Conditional Decision Statements

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

Selection Victor Norman CS104 Calvin College. Reading Quiz Counts toward your grade.
Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 8 Fruitful Functions 05/02/09 Python Mini-Course: Day 2 - Lesson 8 1.
Overview Program flow Decision / branching / selection structures True & False in Python Comparison operators & Boolean expressions if … if … else if …
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
The If/Else Statement, Boolean Flags, and Menus Page 180
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.
CSci 125 Lecture 10 Martin van Bommel. Simple Statements Expression followed by semicolon Assignments total = n1 + n2; Function calls printf(”Hello.\n”);
Python Lab: Control Statements Conditionals, Loops, Iterations Proteomics Informatics, Spring 2014 Week 4 18 th Feb, 2014
Walk through previous lecture. TSP Questions: How many tours are there? How do you solve it? How fast can you solve it?
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.
Introduction to Computing Using Python Imperative Programming  what is a Python program?  print() statement  input() statement  type conversion statements.
Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 7 Conditionals and Loops 4/18/09 Python Mini-Course: Day 2 - Lesson 7.
Python Conditionals chapter 5
Python – Part 3 Functions 1. Getting help Start the Python interpreter and type help() to start the online help utility. Or you can type help(print) to.
CONDITIONALS. Boolean values Boolean value is either true or false It is name after the British mathemetician, George Boole who first formulated Boolean.
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.
A: A: double “4” A: “34” 4.
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
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)
Solution of Mid. Term 2009 Consider the following C++ declarations and assignments. int i, j, k ; float x, y ; char c ; bool test ; i = 35 ; j= 5 ; k =
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)
CS 139 – Programming Fundamentals Lecture 08A. Relational/comparison Operators Relational Operator Meaning > is greater than < is less than >= is greater.
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.
Types, Truth, and Expressions Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Types, Truth, and Expressions Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
 Type Called bool  Bool has only two possible values: True and False.
Python Basics.
Control Flow (Python) Dr. José M. Reyes Álamo.
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Introduction to Python
Topic: Conditional Statements – Part 2
Basic operators - strings
Review Operation Bingo
Imperative Programming
Intro to Computer Science CS1510 Dr. Sarah Diesburg
And now for something completely different . . .
Bools and simple if statements
Types, Truth, and Expressions (Part 2)
Nate Brunelle Today: Repetition, A Trip To The Moon
Types, Truth, and Expressions (Part 2)
Nate Brunelle Today: Repetition, Repetition
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
Program Flow Control Selection & repetition
If Statements.
Nate Brunelle Today: Values and Types
Nate Brunelle Today: Conditional Decision Statements
Types, Truth, and Expressions (Part 2)
Nate Brunelle Today: Functions
Nate Brunelle Today: Strings, Type Casting
Nate Brunelle Today: Values and Types
Understanding Conditions
Nate Brunelle Today: Conditional Decision Statements
ECS15 boolean.
Types, Truth, and Expressions
Nate Brunelle Today: Functions
Nate Brunelle Today: Strings, Type Casting
Nate Brunelle Today: Functions again, Scope
Imperative Programming
COMPUTING.
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions
Control 9 / 25 / 19.
Presentation transcript:

Nate Brunelle Today: Conditional Decision Statements CS1110 Nate Brunelle Today: Conditional Decision Statements

Questions?

Last Time If, elif, else

Conditional decision Statement if boolean expression: action elif boolean expression: another action else: yet another action 0 or more 0 or 1

Values and Types (not exhaustive) Operators -50 ,0 ,5, 30, 512 int 3+7, 3*7, 3-7, 3/7 0.5, 1.2, 0.333333 float +, *, -, /, //, %, **, compare ‘hi’, “hi”, ‘hello world! ✃’ str +, * int Print, input function print() True, False bool and, or, not

and, or, not examples x<2 and x>0 x<0 or x>2 not x>2 When all things are true X=1 x<0 or x>2 When any of the things are true X=-1 X=15 X=2 X=0 not x>2 When the thing is false

and, or, not and or not True if all things are True False if any things are False or True if any things are True False if all things are False not True if the thing was False False if the thing was True

Leap year rules Year is divisible by 4 Unless divisible by 100 div400 or (div4 and not div100)

“Truthiness” of all things in python “Truish” Things “Falsish” things True False “True” 1, -1 0.0 0.0000001 None “ “ Empty things “False” ‘’ “” Advice: make sure every and, or has a bool on both sides

What do and, or evaluate to? Evaluate to the first truish thing If all things are falsish, give the last falsish thing And Give the first falsish thing If all things are truish, give the last truish thing

Chained Comparitors 1 < 2 < 3 1 < 2 and 2 < 3 True 1 < 2 < 3 1 < 2 and 2 < 3 1 < 2 > 0 < 8 > -5 == -5 Gives true True