Python Programming: An Introduction To …
[Pages:25]Python Programming: An Introduction
To Computer Science
Chapter 8 Booleans
Coming up: Computing with
1
Booleans
Computing with Booleans
?!if and while both use Boolean expressions.
?! Boolean expressions evaluate to True or False.
?! So far we've used Boolean expressions to compare two values, e.g. (while x >= 0)
Boolean Operators
?! The Boolean operators and and or are used to combine two Boolean expressions and produce a Boolean result.
?! and ?! or
Expressions versus Statements
?! In the last slide we used the term "expression".
?! The difference between an expression and a statement is:
?!Expressions are something (they evaluate to a value)
?! e.g. x*7+(y**3) , t==True or v1 != v2
?!Statements do something
?! print "hello" ?! x = x * 7
Statement or Expression
?! x = 9 ?! 45 % 78 == 0 ?! myFunction(`potato') ?! x, y = 5, 6 ?! print "%20s" %(`potato') ?! "%20s" %(`potato')
Statement Expression Statement Statement Statement Expression
Boolean Operators
?! The Boolean operators and and or are used to combine two Boolean expressions and produce a Boolean result.
?! and ?! or
Boolean Operators
?! The and of two expressions is true exactly when both of the expressions are true.
?! We can represent this in a truth table.
P Q P and Q P or Q
TT T
T
TF F
T
FT F
T
FF F
F
Boolean Expressions
?! The only time and is true is when both expressions are true
?! The only time or is false is when both expressions are false.
?! Also, note that or is true when both expressions are true. This isn't how we normally use "or" in language.
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- operators and expressions
- booleans university of texas at austin
- python tutorial
- boolean expressions and if
- python programming an introduction to
- concepts in this slide real life examples for making
- python fundamentals
- 5 conditionals — how to think like a computer
- python activity 5 boolean expressions and
- booleans and conditionals
Related searches
- an introduction to marketing pdf
- an introduction to moral philosophy
- an introduction to business
- an introduction to r pdf
- an introduction to an essay
- an introduction to linguistics
- an introduction to formal logic
- an introduction to information retrieval
- an introduction to hazardous materials
- an introduction to literature pdf
- an introduction to community development
- chapter 8 an introduction to metabolism key