CONDITIONALS. Boolean values Boolean value is either true or false It is name after the British mathemetician, George Boole who first formulated Boolean.

Slides:



Advertisements
Similar presentations
CSC 142 G 1 CSC 142 Conditionals [Reading: chapter 5]
Advertisements

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.
Lecture # 21 Chapter 6 Uptill 6.4. Type System A type system is a collection of rules for assigning type expressions to the various parts of the program.
Conditional statements and Boolean expressions. The if-statement in Java (1) The if-statement is a conditional statement The statement is executed only.
CS-1010 Dr. Mark L. Hornick 1 Selection Statements and conditional expressions.
Conditional Statements Introduction to Computing Science and Programming I.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
1 Objectives You should be able to describe: Relational Expressions The if-else Statement Nested if Statements The switch Statement Common Programming.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
2-1 Making Decisions Sample assignment statements PayAmount = Hours * Rate PayAmount = 40*Rate + (Hours – 40)*Rate*1.5.
If Statements Sections 1.25, Control Structures o All code thus far executes every line of code sequentially o We want to be able to repeat,
Lecture 11. Today’s topic Conditional statement –Relational operators –if statement –if-else statement –If-elseif statement.
CS 117 Spring 2002 Review for Exam 2 March 6, 2002 open book, 1 page of notes.
The If/Else Statement, Boolean Flags, and Menus Page 180
Selection. Computer Programming 2 Objectives Examine if statement in more detail Study use of switch statement to implement multialternative selections.
Introduction to Python and programming Michael Ernst UW CSE 190p Summer 2012.
Computer Science 101 Boolean Algebra. What’s next? A new type of algebra – Helps us A new type of algebra – Helps us With logical reasoningWith logical.
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
Data types and their representation Jordi Cortadella Department of Computer Science.
Computer Science 210 Computer Organization Introduction to Boolean Algebra.
Making Decisions (True or False) Relational Operators >greater than =greater than or equal to
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X1 Chapter 3 Control Statements.
Introduction to Python and programming Ruth Anderson UW CSE 140 Winter
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.
Chapter Making Decisions 4. Relational Operators 4.1.
Boolean Values The true story ;=P. Expressions.
“Great leaders are never satisfied with current levels of performance. They are restlessly driven by possibilities and potential achievements.” – Donna.
Laws of Boolean Algebra Commutative Law Associative Law Distributive Law Identity Law De Morgan's Theorem.
Booleans Lecture 26. Summary of previous lecture In the previous lecture, we have been learnt,  The if statement  The else statement  Cascaded if 
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
BOOLEAN OPERATIONS AND CONDITIONALS CHAPTER 20 1.
Lesson thirteen Conditional Statement "if- else" ©
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)
Python Basics  Values, Types, Variables, Expressions  Assignments  I/O  Control Structures.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
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.
Control Structures- Decisions. Smart Computers Computer programs can be written to make computers seem smart Making computers smart is based on decision.
Python Basics.
Control Structures I Chapter 3
Computer Science 210 Computer Organization
Selection (also known as Branching) Jumail Bin Taliba by
Decisions Chapter 4.
Introduction to Python and programming
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Topics The if Statement The if-else Statement Comparing Strings
Type boolean boolean: A logical type whose values are true and false.
Introduction To Robot Decision Making
Topics The if Statement The if-else Statement Comparing Strings
Introduction to Python and programming
And now for something completely different . . .
2-1 Making Decisions Sample assignment statements
Introduction to Python and programming
Bools and simple if statements
Bits and Bytes Boolean algebra Expressing in C
Computer Science 210 Computer Organization
Introduction to Python and programming
Introduction To Robot Decision Making
Nate Brunelle Today: Conditional Decision Statements
Nate Brunelle Today: Conditional Decision Statements
ECS15 boolean.
Decisions, decisions, decisions
Java’s Central Casting
Nate Brunelle Today: Conditional Decision Statements
Introduction to Python and programming
Conditionals.
Presentation transcript:

CONDITIONALS

Boolean values Boolean value is either true or false It is name after the British mathemetician, George Boole who first formulated Boolean Algebra

Boolean expressions Boolean expression is an expression that evaluates to produce a result which a Boolean value.

Six common comparison operators

Boolean can be assigned to variables, printed, etc

Logical Operators

Conditional execution

Omitting the else clause

Chained conditionals

Nested Conditionals

The return statement with or without a value, depending on whether the function is fruitful or void. Allow to terminate the execution of a function before reach the end. One reason to use an early return is if an error condition was detected.

The return statement

Logical opposites OperatorLogical Opposite ==!= == <>= <=> > >=<

Logical opposites

de Morgan’s laws Two powerful simplified laws called de Morgan’s laws that are often helpful for complicated Boolean expressions. not (x and y) == (not x) or (not y) not (x or y) == (not x) and (not y)

Type conversion Many Python types come with a built-in function that attempts to convert values of another type into its own type. – int function – float function – str function

float function

str function

A Turtle Bar Chart