SlideShare uma empresa Scribd logo
1 de 11
 True or False?
 Boolean values are abstract concepts used in
computations.
 TRUE!
 Named in honor of George Boole who invented
a system of mathematics in which the abstract
concepts of true and false can be used in
computations
 Sometimes a program needs to ”decide” whether
or not to execute certain instructions
 All previous instructions have been consecutive
(sequence structure), that is:
 One
 After
 The
 Other
 in the order that they
appear.
 Now we can add some variability, interactivity,
and dynamisms into our applications.
 A conditional is what we refer to as a decision
structure. A decision is made is based upon a set of
rules. We mainly will be working with the if…then.
 An If decision executes a set of instructions if a
Boolean condition is true
 Instruction tests a condition
 The condition controls how the
application executes
 Ex.
 If an event occurs then a certain
outcome will happen.
 If it rains, then I will wear a rain coat.
 Conditional arguments are Boolean expressions.
 We use relational operators to form Boolean
statements.
 Operator Meaning
 == equal to
 < less than
 <= less than or equals to
 > greater than
 >= greater than or equal to
 != not equal to
 Common Mistake: Confusing = with ==
 Code:
Creating a decision structure:
if (expression):
statement
 To execute more than one statement in a block they must be indented
equally:
if (score > 90):
grade = 'A'
print(“Good Job!n”)
print(“Not part of the conditions execution”)
 Good Programming: Commenting conditional blocks
 Common Mistakes: Forgetting equal indent, forgetting :, forgetting
space after if
 Good Practices: Use a tab not a space (easier to line up and
troubleshoot)
Space
Indent
 Code:
 Creating a button object
 GPIO.setup(pin# , GPIO.IN)
 Using button functions to determine if
triggered
 if (GPIO.input(pin#) == False):
Command
Command
 We can nest conditional statements to have several decisions
structures evaluated within one decision tree.
 This allows an application to check multiple situations for a
single desired outcome.
 With an if statement if it evaluates to true it is true the body
statements executed
 However, with an else it will execute when the if statement is
false
 If and else compliment each other
 50/50
 Two halves of the same coin
 Ie. If an event occurs then a certain outcome will happen, else do
something different.
 Ex.
 If it rains, then I will wear a rain coat, else I don’t need a jacket
 Flipping a coin. If it is heads I win, else it is tails I lose(100%
outcomes)
 Code:
Creating a nested decision structure:
if (expression):
statement
else:
statement
 Good Programming: Lining up the else with the
preceding if.
 Common Mistakes: Forgetting the : after the else
Conditionals

Mais conteúdo relacionado

Semelhante a Conditionals

Ap Power Point Chpt3 B
Ap Power Point Chpt3 BAp Power Point Chpt3 B
Ap Power Point Chpt3 B
dplunkett
 
1.4 conditions and loops
1.4   conditions and loops1.4   conditions and loops
1.4 conditions and loops
allenbailey
 
Ap Power Point Chpt3
Ap Power Point Chpt3Ap Power Point Chpt3
Ap Power Point Chpt3
dplunkett
 

Semelhante a Conditionals (20)

jhtp9_ch04.ppt
jhtp9_ch04.pptjhtp9_ch04.ppt
jhtp9_ch04.ppt
 
Ite295 excel if-stmtdsmithfinal
Ite295 excel if-stmtdsmithfinalIte295 excel if-stmtdsmithfinal
Ite295 excel if-stmtdsmithfinal
 
4. decision making and some basic problem
4. decision making and some basic problem4. decision making and some basic problem
4. decision making and some basic problem
 
Chapter 3 introduction to algorithms handouts (with notes)
Chapter 3 introduction to algorithms handouts (with notes)Chapter 3 introduction to algorithms handouts (with notes)
Chapter 3 introduction to algorithms handouts (with notes)
 
07 flow control
07   flow control07   flow control
07 flow control
 
Lecture 07.pptx
Lecture 07.pptxLecture 07.pptx
Lecture 07.pptx
 
C# conditional branching statement
C# conditional branching statementC# conditional branching statement
C# conditional branching statement
 
Ap Power Point Chpt3 B
Ap Power Point Chpt3 BAp Power Point Chpt3 B
Ap Power Point Chpt3 B
 
M C6java5
M C6java5M C6java5
M C6java5
 
1.4 conditions and loops
1.4   conditions and loops1.4   conditions and loops
1.4 conditions and loops
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)
 
Ap Power Point Chpt3
Ap Power Point Chpt3Ap Power Point Chpt3
Ap Power Point Chpt3
 
Cucumber presentation
Cucumber presentationCucumber presentation
Cucumber presentation
 
Functional Effects - Part 2
Functional Effects - Part 2Functional Effects - Part 2
Functional Effects - Part 2
 
C programming
C programmingC programming
C programming
 
VBscript
VBscriptVBscript
VBscript
 
Conditional statements & Loops
Conditional statements & LoopsConditional statements & Loops
Conditional statements & Loops
 
05. Conditional Statements
05. Conditional Statements05. Conditional Statements
05. Conditional Statements
 
03a control structures
03a   control structures03a   control structures
03a control structures
 
Unit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptxUnit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptx
 

Mais de primeteacher32

Mais de primeteacher32 (20)

Software Development Life Cycle
Software Development Life CycleSoftware Development Life Cycle
Software Development Life Cycle
 
Variable Scope
Variable ScopeVariable Scope
Variable Scope
 
Returning Data
Returning DataReturning Data
Returning Data
 
Intro to Functions
Intro to FunctionsIntro to Functions
Intro to Functions
 
Introduction to GUIs with guizero
Introduction to GUIs with guizeroIntroduction to GUIs with guizero
Introduction to GUIs with guizero
 
Function Parameters
Function ParametersFunction Parameters
Function Parameters
 
Nested Loops
Nested LoopsNested Loops
Nested Loops
 
Conditional Loops
Conditional LoopsConditional Loops
Conditional Loops
 
Introduction to Repetition Structures
Introduction to Repetition StructuresIntroduction to Repetition Structures
Introduction to Repetition Structures
 
Input Validation
Input ValidationInput Validation
Input Validation
 
Windows File Systems
Windows File SystemsWindows File Systems
Windows File Systems
 
Nesting Conditionals
Nesting ConditionalsNesting Conditionals
Nesting Conditionals
 
Intro to Python with GPIO
Intro to Python with GPIOIntro to Python with GPIO
Intro to Python with GPIO
 
Variables and Statements
Variables and StatementsVariables and Statements
Variables and Statements
 
Variables and User Input
Variables and User InputVariables and User Input
Variables and User Input
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Raspberry Pi
Raspberry PiRaspberry Pi
Raspberry Pi
 
Hardware vs. Software Presentations
Hardware vs. Software PresentationsHardware vs. Software Presentations
Hardware vs. Software Presentations
 
Block chain security
Block chain securityBlock chain security
Block chain security
 
Hashes
HashesHashes
Hashes
 

Último

K Venkat Naveen Kumar | GCP Data Engineer | CV
K Venkat Naveen Kumar | GCP Data Engineer | CVK Venkat Naveen Kumar | GCP Data Engineer | CV
K Venkat Naveen Kumar | GCP Data Engineer | CV
K VENKAT NAVEEN KUMAR
 
Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...
nirzagarg
 
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...
gajnagarg
 
Top profile Call Girls In Shimla [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Shimla [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Shimla [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Shimla [ 7014168258 ] Call Me For Genuine Models We...
gajnagarg
 
Top profile Call Girls In Raipur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Raipur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Raipur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Raipur [ 7014168258 ] Call Me For Genuine Models We...
gajnagarg
 
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制
yynod
 
怎样办理加利福尼亚大学伯克利分校毕业证(UC Berkeley毕业证书)成绩单学校原版复制
怎样办理加利福尼亚大学伯克利分校毕业证(UC Berkeley毕业证书)成绩单学校原版复制怎样办理加利福尼亚大学伯克利分校毕业证(UC Berkeley毕业证书)成绩单学校原版复制
怎样办理加利福尼亚大学伯克利分校毕业证(UC Berkeley毕业证书)成绩单学校原版复制
yynod
 
Top profile Call Girls In daman [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In daman [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In daman [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In daman [ 7014168258 ] Call Me For Genuine Models We ...
gajnagarg
 
Gabriel_Carter_EXPOLRATIONpp.pptx........
Gabriel_Carter_EXPOLRATIONpp.pptx........Gabriel_Carter_EXPOLRATIONpp.pptx........
Gabriel_Carter_EXPOLRATIONpp.pptx........
deejay178
 
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...
gajnagarg
 
Top profile Call Girls In Rampur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rampur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Rampur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rampur [ 7014168258 ] Call Me For Genuine Models We...
nirzagarg
 
Cara Gugurkan Kandungan Awal Kehamilan 1 bulan (087776558899)
Cara Gugurkan Kandungan Awal Kehamilan 1 bulan (087776558899)Cara Gugurkan Kandungan Awal Kehamilan 1 bulan (087776558899)
Cara Gugurkan Kandungan Awal Kehamilan 1 bulan (087776558899)
Cara Menggugurkan Kandungan 087776558899
 
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
ZurliaSoop
 
Top profile Call Girls In chittoor [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In chittoor [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In chittoor [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In chittoor [ 7014168258 ] Call Me For Genuine Models ...
gajnagarg
 

Último (20)

Specialize in a MSc within Biomanufacturing, and work part-time as Process En...
Specialize in a MSc within Biomanufacturing, and work part-time as Process En...Specialize in a MSc within Biomanufacturing, and work part-time as Process En...
Specialize in a MSc within Biomanufacturing, and work part-time as Process En...
 
Vip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime Malegaon
Vip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime MalegaonVip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime Malegaon
Vip Malegaon Escorts Service Girl ^ 9332606886, WhatsApp Anytime Malegaon
 
Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.
 
K Venkat Naveen Kumar | GCP Data Engineer | CV
K Venkat Naveen Kumar | GCP Data Engineer | CVK Venkat Naveen Kumar | GCP Data Engineer | CV
K Venkat Naveen Kumar | GCP Data Engineer | CV
 
Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...
 
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...
 
Top profile Call Girls In Shimla [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Shimla [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Shimla [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Shimla [ 7014168258 ] Call Me For Genuine Models We...
 
B.tech civil major project by Deepak Kumar
B.tech civil major project by Deepak KumarB.tech civil major project by Deepak Kumar
B.tech civil major project by Deepak Kumar
 
Top profile Call Girls In Raipur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Raipur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Raipur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Raipur [ 7014168258 ] Call Me For Genuine Models We...
 
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制
怎样办理哥伦比亚大学毕业证(Columbia毕业证书)成绩单学校原版复制
 
B.tech Civil Engineering Major Project by Deepak Kumar ppt.pdf
B.tech Civil Engineering Major Project by Deepak Kumar ppt.pdfB.tech Civil Engineering Major Project by Deepak Kumar ppt.pdf
B.tech Civil Engineering Major Project by Deepak Kumar ppt.pdf
 
怎样办理加利福尼亚大学伯克利分校毕业证(UC Berkeley毕业证书)成绩单学校原版复制
怎样办理加利福尼亚大学伯克利分校毕业证(UC Berkeley毕业证书)成绩单学校原版复制怎样办理加利福尼亚大学伯克利分校毕业证(UC Berkeley毕业证书)成绩单学校原版复制
怎样办理加利福尼亚大学伯克利分校毕业证(UC Berkeley毕业证书)成绩单学校原版复制
 
Top profile Call Girls In daman [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In daman [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In daman [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In daman [ 7014168258 ] Call Me For Genuine Models We ...
 
Novo Nordisk Kalundborg. We are expanding our manufacturing hub in Kalundborg...
Novo Nordisk Kalundborg. We are expanding our manufacturing hub in Kalundborg...Novo Nordisk Kalundborg. We are expanding our manufacturing hub in Kalundborg...
Novo Nordisk Kalundborg. We are expanding our manufacturing hub in Kalundborg...
 
Gabriel_Carter_EXPOLRATIONpp.pptx........
Gabriel_Carter_EXPOLRATIONpp.pptx........Gabriel_Carter_EXPOLRATIONpp.pptx........
Gabriel_Carter_EXPOLRATIONpp.pptx........
 
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...
 
Top profile Call Girls In Rampur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rampur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Rampur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rampur [ 7014168258 ] Call Me For Genuine Models We...
 
Cara Gugurkan Kandungan Awal Kehamilan 1 bulan (087776558899)
Cara Gugurkan Kandungan Awal Kehamilan 1 bulan (087776558899)Cara Gugurkan Kandungan Awal Kehamilan 1 bulan (087776558899)
Cara Gugurkan Kandungan Awal Kehamilan 1 bulan (087776558899)
 
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
 
Top profile Call Girls In chittoor [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In chittoor [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In chittoor [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In chittoor [ 7014168258 ] Call Me For Genuine Models ...
 

Conditionals

  • 1.
  • 2.  True or False?  Boolean values are abstract concepts used in computations.  TRUE!  Named in honor of George Boole who invented a system of mathematics in which the abstract concepts of true and false can be used in computations
  • 3.  Sometimes a program needs to ”decide” whether or not to execute certain instructions  All previous instructions have been consecutive (sequence structure), that is:  One  After  The  Other  in the order that they appear.  Now we can add some variability, interactivity, and dynamisms into our applications.
  • 4.  A conditional is what we refer to as a decision structure. A decision is made is based upon a set of rules. We mainly will be working with the if…then.  An If decision executes a set of instructions if a Boolean condition is true  Instruction tests a condition  The condition controls how the application executes  Ex.  If an event occurs then a certain outcome will happen.  If it rains, then I will wear a rain coat.
  • 5.  Conditional arguments are Boolean expressions.  We use relational operators to form Boolean statements.  Operator Meaning  == equal to  < less than  <= less than or equals to  > greater than  >= greater than or equal to  != not equal to  Common Mistake: Confusing = with ==
  • 6.  Code: Creating a decision structure: if (expression): statement  To execute more than one statement in a block they must be indented equally: if (score > 90): grade = 'A' print(“Good Job!n”) print(“Not part of the conditions execution”)  Good Programming: Commenting conditional blocks  Common Mistakes: Forgetting equal indent, forgetting :, forgetting space after if  Good Practices: Use a tab not a space (easier to line up and troubleshoot) Space Indent
  • 7.
  • 8.  Code:  Creating a button object  GPIO.setup(pin# , GPIO.IN)  Using button functions to determine if triggered  if (GPIO.input(pin#) == False): Command Command
  • 9.  We can nest conditional statements to have several decisions structures evaluated within one decision tree.  This allows an application to check multiple situations for a single desired outcome.  With an if statement if it evaluates to true it is true the body statements executed  However, with an else it will execute when the if statement is false  If and else compliment each other  50/50  Two halves of the same coin  Ie. If an event occurs then a certain outcome will happen, else do something different.  Ex.  If it rains, then I will wear a rain coat, else I don’t need a jacket  Flipping a coin. If it is heads I win, else it is tails I lose(100% outcomes)
  • 10.  Code: Creating a nested decision structure: if (expression): statement else: statement  Good Programming: Lining up the else with the preceding if.  Common Mistakes: Forgetting the : after the else