Python – Programs on Logical Operators

Program to check the Number Divisible by both 3 and 5:

n = int(input(“enter number : “))
if n%3==0 and n%5==0:
    print(“Divisible by 3 and 5”)
else:
    print(“Not divisible”)

Check the person age between 20 and 50:

age = int(input(“enter age : “))
if age>=20 and age<=50:
    print(“Age between 20 and 50”)
else:
    print(“Not in between”)

Check the Number is Single Digit or Not:

n = int(input(“enter num : “))
if n>=0 and n<=9:
    print(“Single Digit”)
else:
    print(“Not Sigle Digit”)

Check the Number is Two Digit or Not:

n = int(input(“enter num : “))
if n>=10 and n<=99:
    print(“Two Digit”)
else:
    print(“Not Two Digit”)

Check the Character is Upper case Alphabet or Not:

ch = input(“enter character : “)
if ch>=’A’ and ch<=’Z’:
    print(“Upper case Alphabet”)
else:
    print(“Not”)

Check the Character is Lower case Alphabet or Not:

ch = input(“enter character : “)
if ch>=’a’ and ch<=’z’:
    print(“Lower case Alphabet”)
else:
    print(“Not”)

Check the Character is Digit or Not:

ch = input(“enter character : “)
if ch>=’0′ and ch<=’9′:
    print(“Digit”)
else:
    print(“Not”)

Character is Vowel or Not:

ch = input(“enter character : “)
if ch==’a’ or ch==’e’ or ch==’i’ or ch==’o’ or ch==’u’:
    print(“Vowel”)
else:
    print(“Not”)

Check the Character is Alphabet or Not:

ch = input(“enter character : “)
if((ch>=’A’ and ch<=’Z’) or (ch>=’a’ and ch<=’z’)):
    print(“Alphabet”)
else:
    print(“Not”)

Check the Student passed in all 3 subjects or not with minimum 35 marks:

subj1 = int(input(“Enter subj1 score: “))
subj2 = int(input(“Enter subj2 score: “))
subj3 = int(input(“Enter subj3 score: “))
if subj1 >= 35 and subj2 >= 35 and subj3 >= 35:
    print(“Pass”)
else:
    print(“Fail”)

Check A greater than both B and C:

print(“Enter 3 numbers : “)
x = int(input())
y = int(input())
z = int(input())
if(x>y and x>z):
    print(“Yes”)
else:
    print(“No”)

Check given 3 numbers equal or not:

print(“Enter 3 numbers : “)
x = int(input())
y = int(input())
z = int(input())
if(x==y and y==z and z==x):
    print(“Equal numbers”)
else:
    print(“Not equal numbers”)

Check given 3 numbers unique (not equal):

print(“Enter 3 numbers : “)
x = int(input())
y = int(input())
z = int(input())
if(x!=y and y!=z and z!=x):
    print(“Unique numbers”)
else:
    print(“Not unique numbers”)

Check any 2 numbers are equal among the given 3 numbers:

print(“Enter 3 numbers : “)
x = int(input())
y = int(input())
z = int(input())
if(x==y or y==z or z==x):
    print(“Any 2 equal”)
else:
    print(“Not equal numbers”)
Scroll to Top