Page 474 - ComputerScience_Class_11
P. 474
Output
Initial value of x: 15
After x += 5: 20
After x -= 3: 17
After x *= 2: 34
After x /= 4: 8.5
After x %= 3: 2.5
After x //= 2: 1.0
After x **= 3: 1.0
12.2.4 Logical Operator
Logical operators are used to perform logical operations on two or more conditions. They evaluate expressions and
return either True or False based on the given conditions. Logical operators are commonly used when a program needs
to check multiple conditions at the same time or control the flow of execution.
The following table shows the logical operators in Python along with their description:
Operator Description
not Returns True if operand is false.
and Returns True if both operands are true.
or Returns True if at least one operand is true.
Program 7: To demonstrate the use of Logical operators.
Program 7.py
File Edit Format Run Options Window Help
# Assigning values to variables
x = 15
y = 10
z = 5
# Logical AND: Returns True if both conditions are True
logical_and_result = (x > y) and (y > z)
print("Logical AND Result:", logical_and_result)
# Logical OR: Returns True if at least one condition is True
logical_or_result = (x < y) or (y > z)
print("Logical OR Result:", logical_or_result)
# Logical NOT: Reverses the result (True becomes False and False becomes True)
logical_not_result = not (x == y)
print("Logical NOT Result:", logical_not_result)
472 Touchpad Computer Science (Ver. 3.0)-XI

