0% found this document useful (0 votes)
9 views2 pages

Logical Operators and Conditionals

The document explains logical operators (AND, OR, NOT) and their truth tables, illustrating how they evaluate conditions. It also covers conditional statements in Python, providing examples such as an age check and using logical operators in conditions. Additionally, it includes practice questions to reinforce understanding of the concepts discussed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Logical Operators and Conditionals

The document explains logical operators (AND, OR, NOT) and their truth tables, illustrating how they evaluate conditions. It also covers conditional statements in Python, providing examples such as an age check and using logical operators in conditions. Additionally, it includes practice questions to reinforce understanding of the concepts discussed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Logical Operators & Conditional Statements

What are Logical Operators?


AND (and): True if both conditions are True
OR (or): True if at least one condition is True
NOT (not): Reverses the Boolean value (True becomes False)

Truth Table - AND


A B A and B
True True True
True False False
False True False
False False False

Truth Table - OR
A B A or B
True True True
True False True
False True True
False False False

Truth Table - NOT


A not A
True False
False True

Python Code Examples


a = True
b = False
print(a and b) # False
print(a or b) # True
print(not a) # False
Conditional Statements
if condition:
# do something
elif another_condition:
# do something else
else:
# fallback

Example: Age Check


age = 18
if age >= 18:
print('You can vote')
else:
print('You are too young')

Logical Operators in Conditions


is_student = True
has_id = False
if is_student and has_id:
print('You get a discount')
else:
print('No discount')

Practice Questions
1. print(True or False and False)
2. if not (5 > 3): print('Hello') else: print('Bye')
3. Write a program to check if a number is positive and even.

Wrap-Up & Summary


- Logical operators help make decisions with multiple conditions.
- Conditional statements control the program flow based on logic.

You might also like