Course Content
How to Add a Virtual Environment in Python
0/1
Set
0/1
Python
About Lesson

Logical operators are used in programming and mathematics to combine or modify boolean values (True or False). In Python, there are three primary logical operators:

1. and operator

Returns True if both operands are True.

Python
'''
enter age of a person and check lic eligibility if person age >=18 and <=45
eligible for lic otherwise not  -- using logical operator
'''
age=int(input("enter age of a person"))
income=int(input("enter income "))

if (age>=18 and age<=45):
    print("you are eligible for LIC")
else:
    print("You are not eligible for LIC")

2. or operator

Returns True if at least one of the operands is True.

Python
'''
Write a program that checks if a person is eligible for LIC if they are
 between 18 and 45 years old or have an income of at least 500,000
 eligible for lic otherwise not  -- using logical operator
'''
age=int(input("enter age of a person"))
income=int(input("enter income "))

if (age>=18 and age<=45) or income>=500000:
    print("you are eligible for LIC")
else:
    print("You are not eligible for LIC")
    
#enter 3 nos print biggest number using logical operator
#2  question find on google of or operator

3. not operator

Returns the opposite boolean value of the operand.

Python
true = 1
if not true:
    print("1")
else:
    print("0")  # Output: 0