Py Lec 1
Py Lec 1
Structures
Third Edition
Chapter 3
Selections
b = (1 > 2)
AdditionQuiz
SimpleIfDemo
SubtractionQuiz
ChineseZodiac
BMI Interpretation
Below 18.5 Underweight
18.5-24.9 Normal
25.0-29.9 Overweight
Above 30.0 Obese
ComputeAndInterpretBMI
ComputeTax
True False not (age > 18) is False, because (age > 18) is True.
False True not (gender == 'M') is True, because (grade == 'M') is False.
False True False (age > 18) and (weight >= 140) is False, because weight > 140)
is False.
Blank
True True True (age > 18) and (weight <= 140) is True, because (age > 18) and
(weight <= 140) are both True.
False True True (age > 34) or (weight >= 150) is False, because (age > 34) and
(weight >= 150) are both False.
Blank
True True True (age > 14) or (weight < 140) is true, because (age > 14) is True.
TestBooleanOperators
Copyright © 2023, 2020 Pearson Education, Inc. All Rights Reserved
Copyright © 2023, 2020 Pearson Education, Inc. All Rights Reserved
Problem: Determining Leap Year?
This program first prompts the user to enter a year as an
int value and checks if it is a leap year.
A year is a leap year if it is divisible by 4 but not by 100, or
it is divisible by 400.
(year % 4 == 0 and year % 100 != 0) or (year %
400 == 0)
LeapYear
Lottery
is equivalent to
y = 1 if x > 0 else -1
expression1 if boolean-expression else expression2
ChineseZodiacUsingMatchCase
Copyright © 2023, 2020 Pearson Education, Inc. All Rights Reserved
Copyright © 2023, 2020 Pearson Education, Inc. All Rights Reserved
Operator Precedence
• +, - (Unary plus and minus)
• **
• not
• *, /, //, %
• ==, !=
• and
• or
PointInCircle