SlideShare a Scribd company logo
1 of 20
Copyright © 2018 Pearson Education, Inc.
C H A P T E R 3
Decision
Structures and
Boolean Logic
Copyright © 2018 Pearson Education, Inc.
Topics
• The if Statement
• The if-else Statement
• Comparing Strings
• Nested Decision Structures and the if-elif-else
Statement
• Logical Operators
• Boolean Variables
• Turtle Graphics: Determining the State of the Turtle
Copyright © 2018 Pearson Education, Inc.
The if Statement
• Control structure: logical design that
controls order in which set of
statements execute
• Sequence structure: set of statements
that execute in the order they appear
• Decision structure: specific action(s)
performed only if a condition exists
• Also known as selection structure
Copyright © 2018 Pearson Education, Inc.
The if Statement (cont’d.)
• In flowchart, diamond represents true/
false condition that must be tested
• Actions can be conditionally executed
• Performed only when a condition is true
• Single alternative decision structure:
provides only one alternative path of
execution
• If condition is not true, exit the structure
Copyright © 2018 Pearson Education, Inc.
The if Statement (cont’d.)
Copyright © 2018 Pearson Education, Inc.
The if Statement (cont’d.)
• Python syntax:
if condition:
Statement
Statement
• First line known as the if clause
• Includes the keyword if followed by condition
• The condition can be true or false
• When the if statement executes, the condition is
tested, and if it is true the block statements are
executed. otherwise, block statements are skipped
Copyright © 2018 Pearson Education, Inc.
Boolean Expressions and Relational
Operators
• Boolean expression: expression tested
by if statement to determine if it is true
or false
• Example: a > b
• true if a is greater than b; false otherwise
• Relational operator: determines whether
a specific relationship exists between
two values
• Example: greater than (>)
Copyright © 2018 Pearson Education, Inc.
Boolean Expressions and Relational
Operators (cont’d.)
• >= and <= operators test more than one
relationship
• It is enough for one of the relationships to exist
for the expression to be true
• == operator determines whether the two
operands are equal to one another
• Do not confuse with assignment operator (=)
• != operator determines whether the two
operands are not equal
Copyright © 2018 Pearson Education, Inc.
Boolean Expressions and Relational
Operators (cont’d.)
Copyright © 2018 Pearson Education, Inc.
Boolean Expressions and Relational
Operators (cont’d.)
• Using a Boolean expression with the >
relational operator
Copyright © 2018 Pearson Education, Inc.
Boolean Expressions and Relational
Operators (cont’d.)
• Any relational operator can be used in a
decision block
• Example: if balance == 0
• Example: if payment != balance
• It is possible to have a block inside
another block
• Example: if statement inside a function
• Statements in inner block must be indented
with respect to the outer block
Copyright © 2018 Pearson Education, Inc.
The if-else Statement
• Dual alternative decision structure: two
possible paths of execution
– One is taken if the condition is true, and the
other if the condition is false
• Syntax: if condition:
statements
else:
other statements
• if clause and else clause must be aligned
• Statements must be consistently indented
Copyright © 2018 Pearson Education, Inc.
The if-else Statement (cont’d.)
Copyright © 2018 Pearson Education, Inc.
The if-else Statement (cont’d.)
Copyright © 2018 Pearson Education, Inc.
Comparing Strings
• Strings can be compared using the ==
and != operators
• String comparisons are case sensitive
• Strings can be compared using >, <, >=,
and <=
• Compared character by character based on
the ASCII values for each character
• If shorter word is substring of longer word,
longer word is greater than shorter word
Copyright © 2018 Pearson Education, Inc.
Comparing Strings (cont’d.)
Copyright © 2018 Pearson Education, Inc.
Nested Decision Structures and the
if-elif-else Statement
• A decision structure can be nested
inside another decision structure
• Commonly needed in programs
• Example:
• Determine if someone qualifies for a loan, they
must meet two conditions:
• Must earn at least $30,000/year
• Must have been employed for at least two years
• Check first condition, and if it is true, check second
condition
Copyright © 2018 Pearson Education, Inc.
Copyright © 2018 Pearson Education, Inc.
Nested Decision Structures and the
if-elif-else Statement (cont’d.)
• Important to use proper indentation in a
nested decision structure
• Important for Python interpreter
• Makes code more readable for programmer
• Rules for writing nested if statements:
• else clause should align with matching if clause
• Statements in each block must be consistently
indented
Copyright © 2018 Pearson Education, Inc.
The if-elif-else Statement
• if-elif-else statement: special version of
a decision structure
• Makes logic of nested decision structures simpler to
write
• Can include multiple elif statements
• Syntax:
if condition_1:
statement(s)
elif condition_2:
statement(s)
elif condition_3:
statement(s)
else
statement(s)
Insert as many elif clauses
as necessary.
Copyright © 2018 Pearson Education, Inc.
The if-elif-else Statement
(cont’d.)
• Alignment used with if-elif-else
statement:
• if, elif, and else clauses are all aligned
• Conditionally executed blocks are consistently
indented
• if-elif-else statement is never required,
but logic easier to follow
• Can be accomplished by nested if-else
• Code can become complex, and indentation can cause
problematic long lines
Copyright © 2018 Pearson Education, Inc.
Copyright © 2018 Pearson Education, Inc.
Logical Operators
• Logical operators: operators that can be
used to create complex Boolean
expressions
• and operator and or operator: binary
operators, connect two Boolean expressions
into a compound Boolean expression
• not operator: unary operator, reverses the
truth of its Boolean operand
Copyright © 2018 Pearson Education, Inc.
The and Operator
• Takes two Boolean expressions as
operands
• Creates compound Boolean expression that is
true only when both sub expressions are true
• Can be used to simplify nested decision
structures
• Truth table for
the and operator
Value of the
Expression
Expression
falsefalse and false
falsefalse and true
falsetrue and false
truetrue and true
Copyright © 2018 Pearson Education, Inc.
The or Operator
• Takes two Boolean expressions as
operands
• Creates compound Boolean expression that is
true when either of the sub expressions is true
• Can be used to simplify nested decision
structures
• Truth table for
the or operator
Value of the
Expression
Expression
falsefalse and false
truefalse and true
truetrue and false
truetrue and true
Copyright © 2018 Pearson Education, Inc.
Short-Circuit Evaluation
• Short circuit evaluation: deciding the
value of a compound Boolean
expression after evaluating only one sub
expression
• Performed by the or and and operators
• For or operator: If left operand is true, compound
expression is true. Otherwise, evaluate right operand
• For and operator: If left operand is false, compound
expression is false. Otherwise, evaluate right
operand
Copyright © 2018 Pearson Education, Inc.
The not Operator
• Takes one Boolean expressions as
operand and reverses its logical value
• Sometimes it may be necessary to place
parentheses around an expression to clarify to
what you are applying the not operator
• Truth table for the not operator
Value of the Expression
false
true
Copyright © 2018 Pearson Education, Inc.
Checking Numeric Ranges with
Logical Operators
• To determine whether a numeric value
is within a specific range of values, use
and
Example: x >= 10 and x <= 20
• To determine whether a numeric value
is outside of a specific range of values,
use or
Example: x < 10 or x > 20
Copyright © 2018 Pearson Education, Inc.
Boolean Variables
• Boolean variable: references one of two
values, True or False
• Represented by bool data type
• Commonly used as flags
• Flag: variable that signals when some
condition exists in a program
• Flag set to False ! condition does not exist
• Flag set to True ! condition exists
Copyright © 2018 Pearson Education, Inc.
Turtle Graphics: Determining the
State of the Turtle
• The turtle.xcor() and turtle.ycor() functions
return the turtle's X and Y coordinates
• Examples of calling these functions in an if
statement:
if turtle.xcor() > 100 and turtle.xcor() < 200:
turtle.goto(0, 0)
if turtle.ycor() < 0:
turtle.goto(0, 0)
Copyright © 2018 Pearson Education, Inc.
Turtle Graphics: Determining the
State of the Turtle
• The turtle.heading() function returns the turtle's
heading. (By default, the heading is returned in
degrees.)
• Example of calling the function in an if statement:
if turtle.heading() >= 90 and turtle.heading() <= 270:
turtle.setheading(180)
Copyright © 2018 Pearson Education, Inc.
Turtle Graphics: Determining the
State of the Turtle
• The turtle.isdown() function returns True if the
pen is down, or False otherwise.
• Example of calling the function in an if statement:
if turtle.isdown():
turtle.penup()
if not(turtle.isdown()):
turtle.pendown()
Copyright © 2018 Pearson Education, Inc.
Turtle Graphics: Determining the
State of the Turtle
• The turtle.isvisible() function returns True if
the turtle is visible, or False otherwise.
• Example of calling the function in an if statement:
if turtle.isvisible():
turtle.hideturtle()
Copyright © 2018 Pearson Education, Inc.
Turtle Graphics: Determining the
State of the Turtle
• When you call turtle.pencolor() without passing
an argument, the function returns the pen's current
color as a string. Example of calling the function in an
if statement:
• When you call turtle.fillcolor() without passing
an argument, the function returns the current fill
color as a string. Example of calling the function in an
if statement:
if turtle.pencolor() == 'red':
turtle.pencolor('blue')
if turtle.fillcolor() == 'blue':
turtle.fillcolor('white')
Copyright © 2018 Pearson Education, Inc.
Turtle Graphics: Determining the
State of the Turtle
• When you call turtle.bgcolor() without passing an
argument, the function returns the current
background color as a string. Example of calling the
function in an if statement:
if turtle.bgcolor() == 'white':
turtle.bgcolor('gray')
Copyright © 2018 Pearson Education, Inc.
Turtle Graphics: Determining the
State of the Turtle
• When you call turtle.pensize() without passing an
argument, the function returns the pen's current size
as a string. Example of calling the function in an if
statement:
if turtle.pensize() < 3:
turtle.pensize(3)
Copyright © 2018 Pearson Education, Inc.
Turtle Graphics: Determining the
State of the Turtle
• When you call turtle.speed() without passing an
argument, the function returns the current animation
speed. Example of calling the function in an if
statement:
if turtle.speed() > 0:
turtle.speed(0)
Copyright © 2018 Pearson Education, Inc.
Turtle Graphics: Determining the
State of the Turtle
• See In the Spotlight: The Hit the Target Game in your
textbook for numerous examples of determining the
state of the turtle.
Copyright © 2018 Pearson Education, Inc.
Summary
• This chapter covered:
• Decision structures, including:
• Single alternative decision structures
• Dual alternative decision structures
• Nested decision structures
• Relational operators and logical operators as used in
creating Boolean expressions
• String comparison as used in creating Boolean
expressions
• Boolean variables
• Determining the state of the turtle in Turtle Graphics
COP 1000C Lab Assignment 3
20 Points
For the following program:
1) Create an algorithm called exemptAlgorithm.txt
2) Create the source code called exempt.py
3) Upload your algorithm and source code to BCOnline.
Exempt
You will be writing a program to determine whether or not a
student is exempt from the final exam in COP1000C.
Your program should do the following:
• Prompt the user for a student’s average and number of days
missed.
Input Validation:
• Average must be between 0 and 100
• Number of days missed cannot be less than 0.
Be sure to validate each value separately!
• Use the following conditions to display a message
indicating whether or not a student is exempt from the final
exam. If exempt, indicate why.
o Average is at least 96
o Average is at least 93 and days missed are less than 3
o Average is at least 90 and student has perfect
attendance
Grading Rubric:
Algorithm (5) ______
Intro (1) ______
Variables (1) ______
• Declaration
• Initialization
Input Validation (3) ______
Selection Structure (10) ______
Sample Output:

More Related Content

Similar to Copyright © 2018 Pearson Education, Inc.C H A P T E R 3.docx

C++ problem solving operators ( conditional operators,logical operators, swit...
C++ problem solving operators ( conditional operators,logical operators, swit...C++ problem solving operators ( conditional operators,logical operators, swit...
C++ problem solving operators ( conditional operators,logical operators, swit...mshakeel44514451
 
Ap Power Point Chpt3
Ap Power Point Chpt3Ap Power Point Chpt3
Ap Power Point Chpt3dplunkett
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selectionOnline
 
Week03
Week03Week03
Week03hccit
 
Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)Muhammad Tahir Bashir
 
9781337102087 ppt ch04
9781337102087 ppt ch049781337102087 ppt ch04
9781337102087 ppt ch04Terry Yoast
 
Chapter 4 Writing Classes
Chapter 4 Writing ClassesChapter 4 Writing Classes
Chapter 4 Writing ClassesDanWooster1
 
Eo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5eEo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5eGina Bullock
 
Eo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5eEo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5eGina Bullock
 
Expert system with python -2
Expert system with python  -2Expert system with python  -2
Expert system with python -2Ahmad Hussein
 
Control statements anil
Control statements anilControl statements anil
Control statements anilAnil Dutt
 
Python for Traders - Introduction to Python for Trading
Python for Traders - Introduction to Python for TradingPython for Traders - Introduction to Python for Trading
Python for Traders - Introduction to Python for TradingMarketcalls
 
W4-DecisionMaking.pdf. python document. CS
W4-DecisionMaking.pdf. python document. CSW4-DecisionMaking.pdf. python document. CS
W4-DecisionMaking.pdf. python document. CSMalikaKhan21
 
Week 1: Getting Your Hands Dirty - Part 1
Week 1: Getting Your Hands Dirty - Part 1Week 1: Getting Your Hands Dirty - Part 1
Week 1: Getting Your Hands Dirty - Part 1Jamshid Hashimi
 
IF & SWITCH (conditional control) in computer science
IF & SWITCH (conditional control) in computer scienceIF & SWITCH (conditional control) in computer science
IF & SWITCH (conditional control) in computer scienceRaianaTabitha
 

Similar to Copyright © 2018 Pearson Education, Inc.C H A P T E R 3.docx (20)

C++ problem solving operators ( conditional operators,logical operators, swit...
C++ problem solving operators ( conditional operators,logical operators, swit...C++ problem solving operators ( conditional operators,logical operators, swit...
C++ problem solving operators ( conditional operators,logical operators, swit...
 
Ap Power Point Chpt3
Ap Power Point Chpt3Ap Power Point Chpt3
Ap Power Point Chpt3
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selection
 
Week03
Week03Week03
Week03
 
Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)
 
Unit II.pptx
Unit II.pptxUnit II.pptx
Unit II.pptx
 
Control structure
Control structureControl structure
Control structure
 
slides03.ppt
slides03.pptslides03.ppt
slides03.ppt
 
9781337102087 ppt ch04
9781337102087 ppt ch049781337102087 ppt ch04
9781337102087 ppt ch04
 
Chapter 4 Writing Classes
Chapter 4 Writing ClassesChapter 4 Writing Classes
Chapter 4 Writing Classes
 
Eo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5eEo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5e
 
Eo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5eEo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5e
 
Expert system with python -2
Expert system with python  -2Expert system with python  -2
Expert system with python -2
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
 
Python for Traders - Introduction to Python for Trading
Python for Traders - Introduction to Python for TradingPython for Traders - Introduction to Python for Trading
Python for Traders - Introduction to Python for Trading
 
W4-DecisionMaking.pdf. python document. CS
W4-DecisionMaking.pdf. python document. CSW4-DecisionMaking.pdf. python document. CS
W4-DecisionMaking.pdf. python document. CS
 
Week 1: Getting Your Hands Dirty - Part 1
Week 1: Getting Your Hands Dirty - Part 1Week 1: Getting Your Hands Dirty - Part 1
Week 1: Getting Your Hands Dirty - Part 1
 
Operators in java
Operators in javaOperators in java
Operators in java
 
IF & SWITCH (conditional control) in computer science
IF & SWITCH (conditional control) in computer scienceIF & SWITCH (conditional control) in computer science
IF & SWITCH (conditional control) in computer science
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 

More from dickonsondorris

Copyright © eContent Management Pty Ltd. Health Sociology Revi.docx
Copyright © eContent Management Pty Ltd. Health Sociology Revi.docxCopyright © eContent Management Pty Ltd. Health Sociology Revi.docx
Copyright © eContent Management Pty Ltd. Health Sociology Revi.docxdickonsondorris
 
Copyright © Pearson Education 2010 Digital Tools in Toda.docx
Copyright © Pearson Education 2010 Digital Tools in Toda.docxCopyright © Pearson Education 2010 Digital Tools in Toda.docx
Copyright © Pearson Education 2010 Digital Tools in Toda.docxdickonsondorris
 
Copyright © Jen-Wen Lin 2018 1 STA457 Time series .docx
Copyright © Jen-Wen Lin 2018   1 STA457 Time series .docxCopyright © Jen-Wen Lin 2018   1 STA457 Time series .docx
Copyright © Jen-Wen Lin 2018 1 STA457 Time series .docxdickonsondorris
 
Copyright © John Wiley & Sons, Inc. All rights reserved..docx
Copyright © John Wiley & Sons, Inc. All rights reserved..docxCopyright © John Wiley & Sons, Inc. All rights reserved..docx
Copyright © John Wiley & Sons, Inc. All rights reserved..docxdickonsondorris
 
Copyright © by The McGraw-Hill Companies, Inc. The Aztec Accou.docx
Copyright © by The McGraw-Hill Companies, Inc. The Aztec Accou.docxCopyright © by The McGraw-Hill Companies, Inc. The Aztec Accou.docx
Copyright © by The McGraw-Hill Companies, Inc. The Aztec Accou.docxdickonsondorris
 
Copyright © Cengage Learning. All rights reserved. CHAPTE.docx
Copyright © Cengage Learning.  All rights reserved. CHAPTE.docxCopyright © Cengage Learning.  All rights reserved. CHAPTE.docx
Copyright © Cengage Learning. All rights reserved. CHAPTE.docxdickonsondorris
 
Copyright © by Holt, Rinehart and Winston. All rights reserved.docx
Copyright © by Holt, Rinehart and Winston. All rights reserved.docxCopyright © by Holt, Rinehart and Winston. All rights reserved.docx
Copyright © by Holt, Rinehart and Winston. All rights reserved.docxdickonsondorris
 
Copyright © 2020 by Jones & Bartlett Learning, LLC, an Ascend .docx
Copyright © 2020 by Jones & Bartlett Learning, LLC, an Ascend .docxCopyright © 2020 by Jones & Bartlett Learning, LLC, an Ascend .docx
Copyright © 2020 by Jones & Bartlett Learning, LLC, an Ascend .docxdickonsondorris
 
Copyright © 2019, American Institute of Certified Public Accou.docx
Copyright © 2019, American Institute of Certified Public Accou.docxCopyright © 2019, American Institute of Certified Public Accou.docx
Copyright © 2019, American Institute of Certified Public Accou.docxdickonsondorris
 
Copyright © 2018 Pearson Education, Inc. All Rights ReservedChild .docx
Copyright © 2018 Pearson Education, Inc. All Rights ReservedChild .docxCopyright © 2018 Pearson Education, Inc. All Rights ReservedChild .docx
Copyright © 2018 Pearson Education, Inc. All Rights ReservedChild .docxdickonsondorris
 
Copyright © 2018 Pearson Education, Inc. C H A P T E R 6.docx
Copyright © 2018 Pearson Education, Inc. C H A P T E R  6.docxCopyright © 2018 Pearson Education, Inc. C H A P T E R  6.docx
Copyright © 2018 Pearson Education, Inc. C H A P T E R 6.docxdickonsondorris
 
Copyright © 2018 Capella University. Copy and distribution o.docx
Copyright © 2018 Capella University. Copy and distribution o.docxCopyright © 2018 Capella University. Copy and distribution o.docx
Copyright © 2018 Capella University. Copy and distribution o.docxdickonsondorris
 
Copyright © 2018 by Steven Levitsky and Daniel.docx
Copyright © 2018 by Steven Levitsky and Daniel.docxCopyright © 2018 by Steven Levitsky and Daniel.docx
Copyright © 2018 by Steven Levitsky and Daniel.docxdickonsondorris
 
Copyright © 2017, 2014, 2011 Pearson Education, Inc. All Right.docx
Copyright © 2017, 2014, 2011 Pearson Education, Inc. All Right.docxCopyright © 2017, 2014, 2011 Pearson Education, Inc. All Right.docx
Copyright © 2017, 2014, 2011 Pearson Education, Inc. All Right.docxdickonsondorris
 
Copyright © 2017 Wolters Kluwer Health Lippincott Williams.docx
Copyright © 2017 Wolters Kluwer Health  Lippincott Williams.docxCopyright © 2017 Wolters Kluwer Health  Lippincott Williams.docx
Copyright © 2017 Wolters Kluwer Health Lippincott Williams.docxdickonsondorris
 
Copyright © 2016, 2013, 2010 Pearson Education, Inc. All Right.docx
Copyright © 2016, 2013, 2010 Pearson Education, Inc. All Right.docxCopyright © 2016, 2013, 2010 Pearson Education, Inc. All Right.docx
Copyright © 2016, 2013, 2010 Pearson Education, Inc. All Right.docxdickonsondorris
 
Copyright © 2017 by University of Phoenix. All rights rese.docx
Copyright © 2017 by University of Phoenix. All rights rese.docxCopyright © 2017 by University of Phoenix. All rights rese.docx
Copyright © 2017 by University of Phoenix. All rights rese.docxdickonsondorris
 
Copyright © 2016 John Wiley & Sons, Inc.Copyright © 20.docx
Copyright © 2016 John Wiley & Sons, Inc.Copyright © 20.docxCopyright © 2016 John Wiley & Sons, Inc.Copyright © 20.docx
Copyright © 2016 John Wiley & Sons, Inc.Copyright © 20.docxdickonsondorris
 
Copyright © 2016 Pearson Education, Inc. .docx
Copyright © 2016 Pearson Education, Inc.                    .docxCopyright © 2016 Pearson Education, Inc.                    .docx
Copyright © 2016 Pearson Education, Inc. .docxdickonsondorris
 
Copyright © 2015 McGraw-Hill Education. All rights reserved. N.docx
Copyright © 2015 McGraw-Hill Education. All rights reserved. N.docxCopyright © 2015 McGraw-Hill Education. All rights reserved. N.docx
Copyright © 2015 McGraw-Hill Education. All rights reserved. N.docxdickonsondorris
 

More from dickonsondorris (20)

Copyright © eContent Management Pty Ltd. Health Sociology Revi.docx
Copyright © eContent Management Pty Ltd. Health Sociology Revi.docxCopyright © eContent Management Pty Ltd. Health Sociology Revi.docx
Copyright © eContent Management Pty Ltd. Health Sociology Revi.docx
 
Copyright © Pearson Education 2010 Digital Tools in Toda.docx
Copyright © Pearson Education 2010 Digital Tools in Toda.docxCopyright © Pearson Education 2010 Digital Tools in Toda.docx
Copyright © Pearson Education 2010 Digital Tools in Toda.docx
 
Copyright © Jen-Wen Lin 2018 1 STA457 Time series .docx
Copyright © Jen-Wen Lin 2018   1 STA457 Time series .docxCopyright © Jen-Wen Lin 2018   1 STA457 Time series .docx
Copyright © Jen-Wen Lin 2018 1 STA457 Time series .docx
 
Copyright © John Wiley & Sons, Inc. All rights reserved..docx
Copyright © John Wiley & Sons, Inc. All rights reserved..docxCopyright © John Wiley & Sons, Inc. All rights reserved..docx
Copyright © John Wiley & Sons, Inc. All rights reserved..docx
 
Copyright © by The McGraw-Hill Companies, Inc. The Aztec Accou.docx
Copyright © by The McGraw-Hill Companies, Inc. The Aztec Accou.docxCopyright © by The McGraw-Hill Companies, Inc. The Aztec Accou.docx
Copyright © by The McGraw-Hill Companies, Inc. The Aztec Accou.docx
 
Copyright © Cengage Learning. All rights reserved. CHAPTE.docx
Copyright © Cengage Learning.  All rights reserved. CHAPTE.docxCopyright © Cengage Learning.  All rights reserved. CHAPTE.docx
Copyright © Cengage Learning. All rights reserved. CHAPTE.docx
 
Copyright © by Holt, Rinehart and Winston. All rights reserved.docx
Copyright © by Holt, Rinehart and Winston. All rights reserved.docxCopyright © by Holt, Rinehart and Winston. All rights reserved.docx
Copyright © by Holt, Rinehart and Winston. All rights reserved.docx
 
Copyright © 2020 by Jones & Bartlett Learning, LLC, an Ascend .docx
Copyright © 2020 by Jones & Bartlett Learning, LLC, an Ascend .docxCopyright © 2020 by Jones & Bartlett Learning, LLC, an Ascend .docx
Copyright © 2020 by Jones & Bartlett Learning, LLC, an Ascend .docx
 
Copyright © 2019, American Institute of Certified Public Accou.docx
Copyright © 2019, American Institute of Certified Public Accou.docxCopyright © 2019, American Institute of Certified Public Accou.docx
Copyright © 2019, American Institute of Certified Public Accou.docx
 
Copyright © 2018 Pearson Education, Inc. All Rights ReservedChild .docx
Copyright © 2018 Pearson Education, Inc. All Rights ReservedChild .docxCopyright © 2018 Pearson Education, Inc. All Rights ReservedChild .docx
Copyright © 2018 Pearson Education, Inc. All Rights ReservedChild .docx
 
Copyright © 2018 Pearson Education, Inc. C H A P T E R 6.docx
Copyright © 2018 Pearson Education, Inc. C H A P T E R  6.docxCopyright © 2018 Pearson Education, Inc. C H A P T E R  6.docx
Copyright © 2018 Pearson Education, Inc. C H A P T E R 6.docx
 
Copyright © 2018 Capella University. Copy and distribution o.docx
Copyright © 2018 Capella University. Copy and distribution o.docxCopyright © 2018 Capella University. Copy and distribution o.docx
Copyright © 2018 Capella University. Copy and distribution o.docx
 
Copyright © 2018 by Steven Levitsky and Daniel.docx
Copyright © 2018 by Steven Levitsky and Daniel.docxCopyright © 2018 by Steven Levitsky and Daniel.docx
Copyright © 2018 by Steven Levitsky and Daniel.docx
 
Copyright © 2017, 2014, 2011 Pearson Education, Inc. All Right.docx
Copyright © 2017, 2014, 2011 Pearson Education, Inc. All Right.docxCopyright © 2017, 2014, 2011 Pearson Education, Inc. All Right.docx
Copyright © 2017, 2014, 2011 Pearson Education, Inc. All Right.docx
 
Copyright © 2017 Wolters Kluwer Health Lippincott Williams.docx
Copyright © 2017 Wolters Kluwer Health  Lippincott Williams.docxCopyright © 2017 Wolters Kluwer Health  Lippincott Williams.docx
Copyright © 2017 Wolters Kluwer Health Lippincott Williams.docx
 
Copyright © 2016, 2013, 2010 Pearson Education, Inc. All Right.docx
Copyright © 2016, 2013, 2010 Pearson Education, Inc. All Right.docxCopyright © 2016, 2013, 2010 Pearson Education, Inc. All Right.docx
Copyright © 2016, 2013, 2010 Pearson Education, Inc. All Right.docx
 
Copyright © 2017 by University of Phoenix. All rights rese.docx
Copyright © 2017 by University of Phoenix. All rights rese.docxCopyright © 2017 by University of Phoenix. All rights rese.docx
Copyright © 2017 by University of Phoenix. All rights rese.docx
 
Copyright © 2016 John Wiley & Sons, Inc.Copyright © 20.docx
Copyright © 2016 John Wiley & Sons, Inc.Copyright © 20.docxCopyright © 2016 John Wiley & Sons, Inc.Copyright © 20.docx
Copyright © 2016 John Wiley & Sons, Inc.Copyright © 20.docx
 
Copyright © 2016 Pearson Education, Inc. .docx
Copyright © 2016 Pearson Education, Inc.                    .docxCopyright © 2016 Pearson Education, Inc.                    .docx
Copyright © 2016 Pearson Education, Inc. .docx
 
Copyright © 2015 McGraw-Hill Education. All rights reserved. N.docx
Copyright © 2015 McGraw-Hill Education. All rights reserved. N.docxCopyright © 2015 McGraw-Hill Education. All rights reserved. N.docx
Copyright © 2015 McGraw-Hill Education. All rights reserved. N.docx
 

Recently uploaded

FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactisticshameyhk98
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111GangaMaiya1
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationNeilDeclaro1
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfstareducators107
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answersdalebeck957
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 

Recently uploaded (20)

FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 

Copyright © 2018 Pearson Education, Inc.C H A P T E R 3.docx

  • 1. Copyright © 2018 Pearson Education, Inc. C H A P T E R 3 Decision Structures and Boolean Logic Copyright © 2018 Pearson Education, Inc. Topics • The if Statement • The if-else Statement • Comparing Strings • Nested Decision Structures and the if-elif-else Statement • Logical Operators • Boolean Variables • Turtle Graphics: Determining the State of the Turtle Copyright © 2018 Pearson Education, Inc. The if Statement • Control structure: logical design that controls order in which set of statements execute
  • 2. • Sequence structure: set of statements that execute in the order they appear • Decision structure: specific action(s) performed only if a condition exists • Also known as selection structure Copyright © 2018 Pearson Education, Inc. The if Statement (cont’d.) • In flowchart, diamond represents true/ false condition that must be tested • Actions can be conditionally executed • Performed only when a condition is true • Single alternative decision structure: provides only one alternative path of execution • If condition is not true, exit the structure Copyright © 2018 Pearson Education, Inc. The if Statement (cont’d.) Copyright © 2018 Pearson Education, Inc. The if Statement (cont’d.)
  • 3. • Python syntax: if condition: Statement Statement • First line known as the if clause • Includes the keyword if followed by condition • The condition can be true or false • When the if statement executes, the condition is tested, and if it is true the block statements are executed. otherwise, block statements are skipped Copyright © 2018 Pearson Education, Inc. Boolean Expressions and Relational Operators • Boolean expression: expression tested by if statement to determine if it is true or false • Example: a > b • true if a is greater than b; false otherwise • Relational operator: determines whether a specific relationship exists between two values • Example: greater than (>)
  • 4. Copyright © 2018 Pearson Education, Inc. Boolean Expressions and Relational Operators (cont’d.) • >= and <= operators test more than one relationship • It is enough for one of the relationships to exist for the expression to be true • == operator determines whether the two operands are equal to one another • Do not confuse with assignment operator (=) • != operator determines whether the two operands are not equal Copyright © 2018 Pearson Education, Inc. Boolean Expressions and Relational Operators (cont’d.) Copyright © 2018 Pearson Education, Inc. Boolean Expressions and Relational Operators (cont’d.) • Using a Boolean expression with the > relational operator
  • 5. Copyright © 2018 Pearson Education, Inc. Boolean Expressions and Relational Operators (cont’d.) • Any relational operator can be used in a decision block • Example: if balance == 0 • Example: if payment != balance • It is possible to have a block inside another block • Example: if statement inside a function • Statements in inner block must be indented with respect to the outer block Copyright © 2018 Pearson Education, Inc. The if-else Statement • Dual alternative decision structure: two possible paths of execution – One is taken if the condition is true, and the other if the condition is false • Syntax: if condition: statements else: other statements
  • 6. • if clause and else clause must be aligned • Statements must be consistently indented Copyright © 2018 Pearson Education, Inc. The if-else Statement (cont’d.) Copyright © 2018 Pearson Education, Inc. The if-else Statement (cont’d.) Copyright © 2018 Pearson Education, Inc. Comparing Strings • Strings can be compared using the == and != operators • String comparisons are case sensitive • Strings can be compared using >, <, >=, and <= • Compared character by character based on the ASCII values for each character • If shorter word is substring of longer word, longer word is greater than shorter word
  • 7. Copyright © 2018 Pearson Education, Inc. Comparing Strings (cont’d.) Copyright © 2018 Pearson Education, Inc. Nested Decision Structures and the if-elif-else Statement • A decision structure can be nested inside another decision structure • Commonly needed in programs • Example: • Determine if someone qualifies for a loan, they must meet two conditions: • Must earn at least $30,000/year • Must have been employed for at least two years • Check first condition, and if it is true, check second condition Copyright © 2018 Pearson Education, Inc. Copyright © 2018 Pearson Education, Inc. Nested Decision Structures and the if-elif-else Statement (cont’d.)
  • 8. • Important to use proper indentation in a nested decision structure • Important for Python interpreter • Makes code more readable for programmer • Rules for writing nested if statements: • else clause should align with matching if clause • Statements in each block must be consistently indented Copyright © 2018 Pearson Education, Inc. The if-elif-else Statement • if-elif-else statement: special version of a decision structure • Makes logic of nested decision structures simpler to write • Can include multiple elif statements • Syntax: if condition_1: statement(s) elif condition_2: statement(s) elif condition_3: statement(s) else statement(s) Insert as many elif clauses as necessary.
  • 9. Copyright © 2018 Pearson Education, Inc. The if-elif-else Statement (cont’d.) • Alignment used with if-elif-else statement: • if, elif, and else clauses are all aligned • Conditionally executed blocks are consistently indented • if-elif-else statement is never required, but logic easier to follow • Can be accomplished by nested if-else • Code can become complex, and indentation can cause problematic long lines Copyright © 2018 Pearson Education, Inc. Copyright © 2018 Pearson Education, Inc. Logical Operators • Logical operators: operators that can be used to create complex Boolean expressions • and operator and or operator: binary
  • 10. operators, connect two Boolean expressions into a compound Boolean expression • not operator: unary operator, reverses the truth of its Boolean operand Copyright © 2018 Pearson Education, Inc. The and Operator • Takes two Boolean expressions as operands • Creates compound Boolean expression that is true only when both sub expressions are true • Can be used to simplify nested decision structures • Truth table for the and operator Value of the Expression Expression falsefalse and false falsefalse and true falsetrue and false truetrue and true
  • 11. Copyright © 2018 Pearson Education, Inc. The or Operator • Takes two Boolean expressions as operands • Creates compound Boolean expression that is true when either of the sub expressions is true • Can be used to simplify nested decision structures • Truth table for the or operator Value of the Expression Expression falsefalse and false truefalse and true truetrue and false truetrue and true Copyright © 2018 Pearson Education, Inc. Short-Circuit Evaluation • Short circuit evaluation: deciding the value of a compound Boolean expression after evaluating only one sub expression • Performed by the or and and operators
  • 12. • For or operator: If left operand is true, compound expression is true. Otherwise, evaluate right operand • For and operator: If left operand is false, compound expression is false. Otherwise, evaluate right operand Copyright © 2018 Pearson Education, Inc. The not Operator • Takes one Boolean expressions as operand and reverses its logical value • Sometimes it may be necessary to place parentheses around an expression to clarify to what you are applying the not operator • Truth table for the not operator Value of the Expression false true Copyright © 2018 Pearson Education, Inc. Checking Numeric Ranges with Logical Operators • To determine whether a numeric value is within a specific range of values, use
  • 13. and Example: x >= 10 and x <= 20 • To determine whether a numeric value is outside of a specific range of values, use or Example: x < 10 or x > 20 Copyright © 2018 Pearson Education, Inc. Boolean Variables • Boolean variable: references one of two values, True or False • Represented by bool data type • Commonly used as flags • Flag: variable that signals when some condition exists in a program • Flag set to False ! condition does not exist • Flag set to True ! condition exists Copyright © 2018 Pearson Education, Inc. Turtle Graphics: Determining the State of the Turtle • The turtle.xcor() and turtle.ycor() functions return the turtle's X and Y coordinates
  • 14. • Examples of calling these functions in an if statement: if turtle.xcor() > 100 and turtle.xcor() < 200: turtle.goto(0, 0) if turtle.ycor() < 0: turtle.goto(0, 0) Copyright © 2018 Pearson Education, Inc. Turtle Graphics: Determining the State of the Turtle • The turtle.heading() function returns the turtle's heading. (By default, the heading is returned in degrees.) • Example of calling the function in an if statement: if turtle.heading() >= 90 and turtle.heading() <= 270: turtle.setheading(180) Copyright © 2018 Pearson Education, Inc. Turtle Graphics: Determining the State of the Turtle • The turtle.isdown() function returns True if the pen is down, or False otherwise.
  • 15. • Example of calling the function in an if statement: if turtle.isdown(): turtle.penup() if not(turtle.isdown()): turtle.pendown() Copyright © 2018 Pearson Education, Inc. Turtle Graphics: Determining the State of the Turtle • The turtle.isvisible() function returns True if the turtle is visible, or False otherwise. • Example of calling the function in an if statement: if turtle.isvisible(): turtle.hideturtle() Copyright © 2018 Pearson Education, Inc. Turtle Graphics: Determining the State of the Turtle • When you call turtle.pencolor() without passing an argument, the function returns the pen's current color as a string. Example of calling the function in an if statement:
  • 16. • When you call turtle.fillcolor() without passing an argument, the function returns the current fill color as a string. Example of calling the function in an if statement: if turtle.pencolor() == 'red': turtle.pencolor('blue') if turtle.fillcolor() == 'blue': turtle.fillcolor('white') Copyright © 2018 Pearson Education, Inc. Turtle Graphics: Determining the State of the Turtle • When you call turtle.bgcolor() without passing an argument, the function returns the current background color as a string. Example of calling the function in an if statement: if turtle.bgcolor() == 'white': turtle.bgcolor('gray') Copyright © 2018 Pearson Education, Inc. Turtle Graphics: Determining the State of the Turtle
  • 17. • When you call turtle.pensize() without passing an argument, the function returns the pen's current size as a string. Example of calling the function in an if statement: if turtle.pensize() < 3: turtle.pensize(3) Copyright © 2018 Pearson Education, Inc. Turtle Graphics: Determining the State of the Turtle • When you call turtle.speed() without passing an argument, the function returns the current animation speed. Example of calling the function in an if statement: if turtle.speed() > 0: turtle.speed(0) Copyright © 2018 Pearson Education, Inc. Turtle Graphics: Determining the State of the Turtle
  • 18. • See In the Spotlight: The Hit the Target Game in your textbook for numerous examples of determining the state of the turtle. Copyright © 2018 Pearson Education, Inc. Summary • This chapter covered: • Decision structures, including: • Single alternative decision structures • Dual alternative decision structures • Nested decision structures • Relational operators and logical operators as used in creating Boolean expressions • String comparison as used in creating Boolean expressions • Boolean variables • Determining the state of the turtle in Turtle Graphics COP 1000C Lab Assignment 3 20 Points For the following program:
  • 19. 1) Create an algorithm called exemptAlgorithm.txt 2) Create the source code called exempt.py 3) Upload your algorithm and source code to BCOnline. Exempt You will be writing a program to determine whether or not a student is exempt from the final exam in COP1000C. Your program should do the following: • Prompt the user for a student’s average and number of days missed. Input Validation: • Average must be between 0 and 100 • Number of days missed cannot be less than 0. Be sure to validate each value separately! • Use the following conditions to display a message indicating whether or not a student is exempt from the final exam. If exempt, indicate why. o Average is at least 96 o Average is at least 93 and days missed are less than 3 o Average is at least 90 and student has perfect attendance Grading Rubric: Algorithm (5) ______
  • 20. Intro (1) ______ Variables (1) ______ • Declaration • Initialization Input Validation (3) ______ Selection Structure (10) ______ Sample Output: