conditionals. boolean values boolean value is either true or false it is name after the british...

24
CONDITIONALS

Upload: lewis-powell

Post on 18-Jan-2016

224 views

Category:

Documents


0 download

TRANSCRIPT

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

CONDITIONALS

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

Boolean values• Boolean value is either true or false• It is name after the British mathemetician, George

Boole who first formulated Boolean Algebra

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

Boolean expressions• Boolean expression is an expression that

evaluates to produce a result which a Boolean value.

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

Six common comparison operators

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

Boolean can be assigned to variables, printed, etc

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

Logical Operators

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

Conditional execution

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

Omitting the else clause

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

Chained conditionals

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

Nested Conditionals

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

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.

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

The return statement

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

Logical oppositesOperator Logical Opposite

== !=!= ==< >=

<= >> <=

>= <

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

Logical opposites

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

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)

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

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

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

int function

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

float function

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

str function

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

A Turtle Bar Chart

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