Understanding Boolean Operators and Control Flow in Programming
Explore the world of Boolean operators and control flow in programming with this detailed chapter. Learn about comparison operators, boolean values, and the logical operators and, or, and not. Understand how these concepts are used to control the flow of your code through practical examples. Dive into the order of operations and grasp the importance of evaluating conditions accurately to make informed decisions in your programming journey.
Download Presentation
Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
E N D
Presentation Transcript
Flow Control (Boolean Operators) Chapter 02a
REVIEW: Use Comparison Operators Comparison Operators for Control Flow Operator == != < > <= >= Meaning Equal to No equal to Less than Greater than Less than or equal to Greater than or equal to >, <, >=, <= work only with integer or floating numbers
REVIEW: Boolean Values Only has two values: True and False Type case exactly as above: Capital T and Capital F.
Boolean Operators and or not
and and Operator when you use and , all conditions must be True if firstCondition and secondCondition: First condition is Second condition is Statement is True True True True False False False True False False False False
or or Operator when you use or, just one condition must be True if firstCondition or secondCondition: First condition is Second condition is Statement is True True True True False True False True True False False False
not not Operator Operator Evaluates to not True False not False True
Order of Operations Math and Comparison Operators not and or
If you win the lottery and the prize is over a million dollars then retire to a life of luxury. Sometimes the decision on whether to take the next step depends on a combination of factors. If I win the lottery, but only win $5 I can t retire. If the lottery give out a million dollars but I didn t win, I can t retire. I can only retire if I win the lottery and the prize was over a million dollars.
The and is only evaluated as True if both conditions are True wonLottery = True bigWin = True #print statement only executes if both conditions are True. if wonLottery and bigWin: print( You can retire )