Logical-Operators-In-If-Statements

Wed 12 November 2025
#  created : 20250125
#  https://www.scientecheasy.com/2022/10/if-statement-in-python.html/
def logical():
    x, y, z = 20, 40, 50
    if((y > x) and (y < z)): # True 
         print("y is greater than x but smaller than z") 
    if((x > y) and (y < z)): # False
         print("z is greater than x, y")
    if(y % x == 0 and x != 0): # True
         print("y is divisible by x")
logical()
y is greater than x but smaller than z
y is divisible by x
def logical1():
    x, y, z = 2, 1, 4
    if(value := x > y or y < z): 
        print(value) 
    if(value := x > y or y > z):
        print(value)

    if(value := x < y or y < z):
        print(value)
    if(value := x < y or y > z):
        print(value)
logical1()
True
True
True
def logical2():
    age = 25
    income =int(input("enter your amount: "))

    if age > 18 and income > 30000:
        print("Eligible for a credit card")
    else:
        print("Not eligible")
logical2()
enter your amount:  40000


Eligible for a credit card
def logical3():
    age = int(input("enter your age:"))
    has_membership = True
    is_guest = False

    if (age > 18 and has_membership) or (age > 18 and is_guest):
        print("Access granted")
    else:
        print("Access denied")
logical3()
enter your age: 23


Access granted


Score: 10

Category: python-basics