SlideShare uma empresa Scribd logo
1 de 26
Unit 3: Python
Lesson 3: Boolean Logic
January 5, 2014
Lesson 3: Boolean Logic
Introduction to
Programming
Lesson 1

Designing a
Game
Lesson 8

Sorting and
Searching
Lesson 9

Hardware &
Software
Lesson 2

Working with
Files
Lesson 7

Advanced
Algorithms
Lesson 10

Boolean Logic
Lesson 3

Loops
Lesson 6

Navigating the
Web (?)
Lesson 11

Functions
Lesson 4

Data Types
Lesson 5

Putting It All
Together
Lesson 12
2
Recap from last time (I)
• Software is electronically stored data that allows us to interact with
our devices
• Hardware is the physical device that we need to interact with our
computer programs

• You can think of software and hardware as two pieces that come
together to make the finished product that we use such as browsing
Google, writing a Word document, or playing Angry Birds on our
iPhone

3
Recap from last time (II)
• Our computer hardware needs software called an operating system
in order to function
• Updating software occurs much more frequently than updating
hardware

• Software communicates with hardware through programming
languages

4
Computers use a very simple vocabulary
• While computers can be programmed to do some amazing things,
they only know a few simple words
• Today, we will look at some of the basic vocabulary that computers
rely upon

5
TRUE and FALSE are the most basic words a
computer will use
• To a computer, the answer to any question will either be TRUE or
FALSE. If a computer asked you if you were hungry, you wouldn’t
say “Yes” or “No” – you would say “TRUE” or “FALSE”
• Using TRUE and FALSE is how computers think, and it’s called
Boolean logic after George Boole, a 19th Century English
mathematician
Are you
hungry?

TRUE

George Boole
6
Combine words with AND, NOT, and OR
• Computers also love to use the words “AND”, “NOT”, and “OR”, but
their meanings can be a little different from how we would use them
• Let’s imagine a restaurant where the menu has only three items

Fish

Chips

Mushy Peas

7
AND means “both”
• “AND” is used just like we would say “And” in English
• If a computer asked if you were hungry for “Fish AND Chips”, it
would want to know if you wanted “Fish and Chips both”

Fish AND
Chips?

Fish and Chips
8
NOT means “Everything except”
• “NOT” to computers is a little different from the English “Not”
• If a computer asked if you were hungry for “NOT Fish”, it would want
to know if you wanted “Everything except Fish”
• Since there are only three items on the menu, this means “Chips
and Mushy Peas”
NOT Fish?

+
Chips

Mushy Peas
9
Remember that OR is a little different (I)
• In English, asking if you want “Fish or Chips” is the same as asking
if you want:
Either

or
Fish only

Chips only

10
Remember that OR is a little different (II)
• In English, asking if you want “Fish or Chips” is the same as asking
if you want:
or
Fish only

Chips only

• But to a computer, asking if you want “Fish OR Chips” is equivalent
to asking if you want:

or
Fish only

or
Chips only

Fish and Chips
11
See if you can figure these out on your own
1. Fish AND Chips AND Mushy Peas

1. NOT Mushy Peas

1. Fish OR Mushy Peas

12
Did you get them right?
1. Fish AND Chips AND Mushy Peas

1. NOT Mushy Peas

Fish and Chips and Mushy Peas
Fish and Chips

1. Fish OR Mushy Peas

or

Fish only

or

Mushy Peas only

Fish and Mushy Peas
13
Let’s see a few more examples
• This time, let’s imagine that the menu has four items for breakfast

Bacon

Eggs

Toast

Tea

14
Combining AND, NOT, and OR can get messy!
1. NOT Tea

2. NOT (Toast AND Tea)

3. Bacon OR Eggs OR Tea

4. (Bacon AND Eggs) OR Toast

15
How did you do?
1. NOT Tea

Bacon, Eggs, and Toast

3. Bacon OR Eggs OR Tea

2. NOT (Toast AND Tea)

Bacon and Eggs

4. (Bacon AND Eggs) OR Toast

or
Any combination of
Bacon, Eggs, and Tea

Bacon and Eggs

or

Toast only

Bacon, Eggs,
and Toast
16
This vocabulary is useful in IF statements (II)
• IF statements allow a computer to behave differently under different
situations
• In the examples below, you’ll see how IF statements use the
vocabulary we just learned
IF statement
if “you are tired”:
“go rest for a while”

Explanation
If “you are tired” is TRUE,
then “go rest for a while”

17
This vocabulary is useful in IF statements (II)
• IF statements allow a computer to behave differently under different
situations
• In the examples below, you’ll see how IF statements use the
vocabulary we just learned
IF statement
if “you are tired”:
“go rest for a while”
if “you are tired” OR “you are sick”:
“go rest for a while”

Explanation
If “you are tired” is TRUE,
then “go rest for a while”
If “you are tired” is TRUE, or
If “you are sick” is TRUE, or
If “you are tired and sick” is TRUE,
then “go rest for a while”
18
You can turn an IF into an IF-ELSE (I)
• We can start with a regular IF statement like in the example below

IF-ELSE statement

Explanation

if “the water looks clean”:
“drink it”

If “the water looks clean” is TRUE,
then “drink it”.

19
You can turn an IF into an IF-ELSE (II)
• By adding an ELSE, you can decide what happens when the IF
statement is FALSE

IF-ELSE statement

Explanation

if “the water looks clean”:
“drink it”

If “the water looks clean” is TRUE,
then “drink it”.

else:
“buy bottled water”

If “the water looks clean” is FALSE,
then “buy bottled water”

20
You can even make it an IF-ELIF-ELSE (I)
• Sometimes you will have more than two cases to choose from. In
these situations, you first start with a regular IF statement
IF-ELIF-ELSE statement
if “Manchester United scored more
goals than Liverpool”:
“Manchester United wins!”

Explanation
If “Manchester United scored more
goals than Liverpool” is TRUE,
then “Manchester United wins!”

21
You can even make it an IF-ELIF-ELSE (II)
• Then we can add on an ELIF to check for a second case
IF-ELIF-ELSE statement

Explanation

if “Manchester United scored more
goals than Liverpool”:
“Manchester United wins!”

If “Manchester United scored more
goals than Liverpool” is TRUE,
then “Manchester United wins!”

elif “Liverpool scored more goals
than Manchester United”:
“Liverpool wins!”

If “Liverpool scored more goals
than Manchester United” is TRUE,
then “Liverpool wins!”

22
You can even make it an IF-ELIF-ELSE (III)
• Finally, we can use an ELSE to handle any other cases
IF-ELIF-ELSE statement

Explanation

if “Manchester United scored more
goals than Liverpool”:
“Manchester United wins!”

If “Manchester United scored more
goals than Liverpool” is TRUE,
then “Manchester United wins!”

elif “Liverpool scored more goals
than Manchester United”:
“Liverpool wins!”

If “Liverpool scored more goals
than Manchester United” is TRUE,
then “Liverpool wins!”

else:
“Break the tie with penalty kicks”

If both statements are FALSE,
then “Use penalty kicks to break
the tie”
23
Summary (I)
• Boolean Logic is a phrase used to describe the way computers think
only in TRUE and FALSE
• AND, NOT, and OR can be used to combine statements together,
but their meanings are a little different from their English meanings

• Remember that OR means one, or the other, or both!

or
Fish only

or
Chips only

Fish and Chips

24
Summary (II)
• IF statements allow a computer to perform differently when in
different situations
• Add ELSE to decide what will happen when the IF statement is
FALSE

• Add ELIF when you have more than two cases to choose from

Manchester United wins!

Liverpool wins!

Penalty kicks
25
What to do on your own
1. Go to URL to complete the Codecademy course online

2. Do the practice set on the material learned

1. Take the follow-up quiz to test your understanding

26

Mais conteúdo relacionado

Mais de Codecademy Ren

Lesson 304 05 jan14-1500-ay
Lesson 304 05 jan14-1500-ayLesson 304 05 jan14-1500-ay
Lesson 304 05 jan14-1500-ayCodecademy Ren
 
Lesson 301 26 nov13-1500-ay
Lesson 301 26 nov13-1500-ayLesson 301 26 nov13-1500-ay
Lesson 301 26 nov13-1500-ayCodecademy Ren
 
Lesson 302 05 jan14-1500-ay
Lesson 302 05 jan14-1500-ayLesson 302 05 jan14-1500-ay
Lesson 302 05 jan14-1500-ayCodecademy Ren
 
Lesson 207 19 oct13-1500-ay
Lesson 207 19 oct13-1500-ayLesson 207 19 oct13-1500-ay
Lesson 207 19 oct13-1500-ayCodecademy Ren
 
Lesson 206 11 oct13-1500-ay
Lesson 206 11 oct13-1500-ayLesson 206 11 oct13-1500-ay
Lesson 206 11 oct13-1500-ayCodecademy Ren
 
Lesson 202 02 oct13-1800-ay
Lesson 202 02 oct13-1800-ayLesson 202 02 oct13-1800-ay
Lesson 202 02 oct13-1800-ayCodecademy Ren
 
Lesson 112 24 aug13-2300-ay
Lesson 112 24 aug13-2300-ayLesson 112 24 aug13-2300-ay
Lesson 112 24 aug13-2300-ayCodecademy Ren
 
Lesson 108 23 aug13-1430-ay
Lesson 108 23 aug13-1430-ayLesson 108 23 aug13-1430-ay
Lesson 108 23 aug13-1430-ayCodecademy Ren
 
Lesson 106 23 aug13-1430-ay
Lesson 106 23 aug13-1430-ayLesson 106 23 aug13-1430-ay
Lesson 106 23 aug13-1430-ayCodecademy Ren
 
Lesson 105 23 aug13-1430-ay
Lesson 105 23 aug13-1430-ayLesson 105 23 aug13-1430-ay
Lesson 105 23 aug13-1430-ayCodecademy Ren
 
Lesson 102 23 aug13-1430-ay
Lesson 102 23 aug13-1430-ayLesson 102 23 aug13-1430-ay
Lesson 102 23 aug13-1430-ayCodecademy Ren
 
Lesson 102 25 aug13-2200-ay
Lesson 102 25 aug13-2200-ayLesson 102 25 aug13-2200-ay
Lesson 102 25 aug13-2200-ayCodecademy Ren
 
Lesson 103 23 aug13-1430-ay
Lesson 103 23 aug13-1430-ayLesson 103 23 aug13-1430-ay
Lesson 103 23 aug13-1430-ayCodecademy Ren
 
Lesson 104 23 aug13-1430-ay
Lesson 104 23 aug13-1430-ayLesson 104 23 aug13-1430-ay
Lesson 104 23 aug13-1430-ayCodecademy Ren
 
Lesson 111 24 aug13-1430-ay
Lesson 111 24 aug13-1430-ayLesson 111 24 aug13-1430-ay
Lesson 111 24 aug13-1430-ayCodecademy Ren
 

Mais de Codecademy Ren (15)

Lesson 304 05 jan14-1500-ay
Lesson 304 05 jan14-1500-ayLesson 304 05 jan14-1500-ay
Lesson 304 05 jan14-1500-ay
 
Lesson 301 26 nov13-1500-ay
Lesson 301 26 nov13-1500-ayLesson 301 26 nov13-1500-ay
Lesson 301 26 nov13-1500-ay
 
Lesson 302 05 jan14-1500-ay
Lesson 302 05 jan14-1500-ayLesson 302 05 jan14-1500-ay
Lesson 302 05 jan14-1500-ay
 
Lesson 207 19 oct13-1500-ay
Lesson 207 19 oct13-1500-ayLesson 207 19 oct13-1500-ay
Lesson 207 19 oct13-1500-ay
 
Lesson 206 11 oct13-1500-ay
Lesson 206 11 oct13-1500-ayLesson 206 11 oct13-1500-ay
Lesson 206 11 oct13-1500-ay
 
Lesson 202 02 oct13-1800-ay
Lesson 202 02 oct13-1800-ayLesson 202 02 oct13-1800-ay
Lesson 202 02 oct13-1800-ay
 
Lesson 112 24 aug13-2300-ay
Lesson 112 24 aug13-2300-ayLesson 112 24 aug13-2300-ay
Lesson 112 24 aug13-2300-ay
 
Lesson 108 23 aug13-1430-ay
Lesson 108 23 aug13-1430-ayLesson 108 23 aug13-1430-ay
Lesson 108 23 aug13-1430-ay
 
Lesson 106 23 aug13-1430-ay
Lesson 106 23 aug13-1430-ayLesson 106 23 aug13-1430-ay
Lesson 106 23 aug13-1430-ay
 
Lesson 105 23 aug13-1430-ay
Lesson 105 23 aug13-1430-ayLesson 105 23 aug13-1430-ay
Lesson 105 23 aug13-1430-ay
 
Lesson 102 23 aug13-1430-ay
Lesson 102 23 aug13-1430-ayLesson 102 23 aug13-1430-ay
Lesson 102 23 aug13-1430-ay
 
Lesson 102 25 aug13-2200-ay
Lesson 102 25 aug13-2200-ayLesson 102 25 aug13-2200-ay
Lesson 102 25 aug13-2200-ay
 
Lesson 103 23 aug13-1430-ay
Lesson 103 23 aug13-1430-ayLesson 103 23 aug13-1430-ay
Lesson 103 23 aug13-1430-ay
 
Lesson 104 23 aug13-1430-ay
Lesson 104 23 aug13-1430-ayLesson 104 23 aug13-1430-ay
Lesson 104 23 aug13-1430-ay
 
Lesson 111 24 aug13-1430-ay
Lesson 111 24 aug13-1430-ayLesson 111 24 aug13-1430-ay
Lesson 111 24 aug13-1430-ay
 

Último

Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Dave Litwiller
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...amitlee9823
 
Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageMatteo Carbone
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1kcpayne
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communicationskarancommunications
 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLSeo
 
Business Model Canvas (BMC)- A new venture concept
Business Model Canvas (BMC)-  A new venture conceptBusiness Model Canvas (BMC)-  A new venture concept
Business Model Canvas (BMC)- A new venture conceptP&CO
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with CultureSeta Wicaksana
 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayNZSG
 
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxB.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxpriyanshujha201
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfAdmir Softic
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...amitlee9823
 
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLBAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLkapoorjyoti4444
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...rajveerescorts2022
 
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...amitlee9823
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...Aggregage
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableDipal Arora
 
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...lizamodels9
 
Monthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxMonthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxAndy Lambert
 

Último (20)

Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
 
Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usage
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communications
 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
 
Business Model Canvas (BMC)- A new venture concept
Business Model Canvas (BMC)-  A new venture conceptBusiness Model Canvas (BMC)-  A new venture concept
Business Model Canvas (BMC)- A new venture concept
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with Culture
 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 May
 
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxB.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
 
Forklift Operations: Safety through Cartoons
Forklift Operations: Safety through CartoonsForklift Operations: Safety through Cartoons
Forklift Operations: Safety through Cartoons
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
 
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLBAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
 
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
 
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
 
Monthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxMonthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptx
 

Lesson 303 05 jan14-1500-ay

  • 1. Unit 3: Python Lesson 3: Boolean Logic January 5, 2014
  • 2. Lesson 3: Boolean Logic Introduction to Programming Lesson 1 Designing a Game Lesson 8 Sorting and Searching Lesson 9 Hardware & Software Lesson 2 Working with Files Lesson 7 Advanced Algorithms Lesson 10 Boolean Logic Lesson 3 Loops Lesson 6 Navigating the Web (?) Lesson 11 Functions Lesson 4 Data Types Lesson 5 Putting It All Together Lesson 12 2
  • 3. Recap from last time (I) • Software is electronically stored data that allows us to interact with our devices • Hardware is the physical device that we need to interact with our computer programs • You can think of software and hardware as two pieces that come together to make the finished product that we use such as browsing Google, writing a Word document, or playing Angry Birds on our iPhone 3
  • 4. Recap from last time (II) • Our computer hardware needs software called an operating system in order to function • Updating software occurs much more frequently than updating hardware • Software communicates with hardware through programming languages 4
  • 5. Computers use a very simple vocabulary • While computers can be programmed to do some amazing things, they only know a few simple words • Today, we will look at some of the basic vocabulary that computers rely upon 5
  • 6. TRUE and FALSE are the most basic words a computer will use • To a computer, the answer to any question will either be TRUE or FALSE. If a computer asked you if you were hungry, you wouldn’t say “Yes” or “No” – you would say “TRUE” or “FALSE” • Using TRUE and FALSE is how computers think, and it’s called Boolean logic after George Boole, a 19th Century English mathematician Are you hungry? TRUE George Boole 6
  • 7. Combine words with AND, NOT, and OR • Computers also love to use the words “AND”, “NOT”, and “OR”, but their meanings can be a little different from how we would use them • Let’s imagine a restaurant where the menu has only three items Fish Chips Mushy Peas 7
  • 8. AND means “both” • “AND” is used just like we would say “And” in English • If a computer asked if you were hungry for “Fish AND Chips”, it would want to know if you wanted “Fish and Chips both” Fish AND Chips? Fish and Chips 8
  • 9. NOT means “Everything except” • “NOT” to computers is a little different from the English “Not” • If a computer asked if you were hungry for “NOT Fish”, it would want to know if you wanted “Everything except Fish” • Since there are only three items on the menu, this means “Chips and Mushy Peas” NOT Fish? + Chips Mushy Peas 9
  • 10. Remember that OR is a little different (I) • In English, asking if you want “Fish or Chips” is the same as asking if you want: Either or Fish only Chips only 10
  • 11. Remember that OR is a little different (II) • In English, asking if you want “Fish or Chips” is the same as asking if you want: or Fish only Chips only • But to a computer, asking if you want “Fish OR Chips” is equivalent to asking if you want: or Fish only or Chips only Fish and Chips 11
  • 12. See if you can figure these out on your own 1. Fish AND Chips AND Mushy Peas 1. NOT Mushy Peas 1. Fish OR Mushy Peas 12
  • 13. Did you get them right? 1. Fish AND Chips AND Mushy Peas 1. NOT Mushy Peas Fish and Chips and Mushy Peas Fish and Chips 1. Fish OR Mushy Peas or Fish only or Mushy Peas only Fish and Mushy Peas 13
  • 14. Let’s see a few more examples • This time, let’s imagine that the menu has four items for breakfast Bacon Eggs Toast Tea 14
  • 15. Combining AND, NOT, and OR can get messy! 1. NOT Tea 2. NOT (Toast AND Tea) 3. Bacon OR Eggs OR Tea 4. (Bacon AND Eggs) OR Toast 15
  • 16. How did you do? 1. NOT Tea Bacon, Eggs, and Toast 3. Bacon OR Eggs OR Tea 2. NOT (Toast AND Tea) Bacon and Eggs 4. (Bacon AND Eggs) OR Toast or Any combination of Bacon, Eggs, and Tea Bacon and Eggs or Toast only Bacon, Eggs, and Toast 16
  • 17. This vocabulary is useful in IF statements (II) • IF statements allow a computer to behave differently under different situations • In the examples below, you’ll see how IF statements use the vocabulary we just learned IF statement if “you are tired”: “go rest for a while” Explanation If “you are tired” is TRUE, then “go rest for a while” 17
  • 18. This vocabulary is useful in IF statements (II) • IF statements allow a computer to behave differently under different situations • In the examples below, you’ll see how IF statements use the vocabulary we just learned IF statement if “you are tired”: “go rest for a while” if “you are tired” OR “you are sick”: “go rest for a while” Explanation If “you are tired” is TRUE, then “go rest for a while” If “you are tired” is TRUE, or If “you are sick” is TRUE, or If “you are tired and sick” is TRUE, then “go rest for a while” 18
  • 19. You can turn an IF into an IF-ELSE (I) • We can start with a regular IF statement like in the example below IF-ELSE statement Explanation if “the water looks clean”: “drink it” If “the water looks clean” is TRUE, then “drink it”. 19
  • 20. You can turn an IF into an IF-ELSE (II) • By adding an ELSE, you can decide what happens when the IF statement is FALSE IF-ELSE statement Explanation if “the water looks clean”: “drink it” If “the water looks clean” is TRUE, then “drink it”. else: “buy bottled water” If “the water looks clean” is FALSE, then “buy bottled water” 20
  • 21. You can even make it an IF-ELIF-ELSE (I) • Sometimes you will have more than two cases to choose from. In these situations, you first start with a regular IF statement IF-ELIF-ELSE statement if “Manchester United scored more goals than Liverpool”: “Manchester United wins!” Explanation If “Manchester United scored more goals than Liverpool” is TRUE, then “Manchester United wins!” 21
  • 22. You can even make it an IF-ELIF-ELSE (II) • Then we can add on an ELIF to check for a second case IF-ELIF-ELSE statement Explanation if “Manchester United scored more goals than Liverpool”: “Manchester United wins!” If “Manchester United scored more goals than Liverpool” is TRUE, then “Manchester United wins!” elif “Liverpool scored more goals than Manchester United”: “Liverpool wins!” If “Liverpool scored more goals than Manchester United” is TRUE, then “Liverpool wins!” 22
  • 23. You can even make it an IF-ELIF-ELSE (III) • Finally, we can use an ELSE to handle any other cases IF-ELIF-ELSE statement Explanation if “Manchester United scored more goals than Liverpool”: “Manchester United wins!” If “Manchester United scored more goals than Liverpool” is TRUE, then “Manchester United wins!” elif “Liverpool scored more goals than Manchester United”: “Liverpool wins!” If “Liverpool scored more goals than Manchester United” is TRUE, then “Liverpool wins!” else: “Break the tie with penalty kicks” If both statements are FALSE, then “Use penalty kicks to break the tie” 23
  • 24. Summary (I) • Boolean Logic is a phrase used to describe the way computers think only in TRUE and FALSE • AND, NOT, and OR can be used to combine statements together, but their meanings are a little different from their English meanings • Remember that OR means one, or the other, or both! or Fish only or Chips only Fish and Chips 24
  • 25. Summary (II) • IF statements allow a computer to perform differently when in different situations • Add ELSE to decide what will happen when the IF statement is FALSE • Add ELIF when you have more than two cases to choose from Manchester United wins! Liverpool wins! Penalty kicks 25
  • 26. What to do on your own 1. Go to URL to complete the Codecademy course online 2. Do the practice set on the material learned 1. Take the follow-up quiz to test your understanding 26