Logical Operators


This code prompts the user to input three numbers (number_1, number_2, and number_3) and stores them as integers. It then checks if number_1 is greater than number_2 and number_3 is greater than number_2 using logical "and" operator. If this condition is true, it prints "First and Third Value is Greater than Second Value" If second condition is true where number_2 is greater than number_1 and number_3 is greater than number_1 it will print "Second and Third Value is Greater than First Value" Otherwise, if none of the conditions are true, it will print "Condition not Satisfied...!"

Source Code : 1

number_1	=int(input("Enter First value : "))
number_2 	=int(input("Enter Second Value : "))
number_3 	=int(input("Enter Third Value : "))

print("Logical AND Example ")
if((number_1 > number_2 ) and (number_3 > number_2 )) :
	print("First and Third Value is Greater than Second Value")
elif((number_2 > number_1 ) and (number_3 > number_1 )) :
    print("Second and Third Value is Greater than First Value")
else:
    print("Condition not Satisfied...!")
    
To download raw file Click Here

Output : 1

Enter First value : 30
Enter Second Value : 20
Enter Third Value : 40

Logical AND Example
First and Third Value is Greater than Second Value

This code prompts the user to input three numbers (number_1, number_2, and number_3) and stores them as integers. It then checks if number_1 is greater than number_2 or number_3 is greater than number_2 using logical "or" operator. If this condition is true, it prints "Second Number is less than First or Third Number" If second condition is true where number_2 is greater than number_1 or number_3 is greater than number_1 it will print "First Number is less than Second or Third Number" Otherwise, if none of the conditions are true, it will print "Condition not Satisfied...!"

Source Code : 2

number_1	=int(input("Enter First value : "))
number_2 	=int(input("Enter Second Value : "))
number_3 	=int(input("Enter Third Value : "))

print("Logical OR Example ")
if((number_1 > number_2 ) or (number_3 > number_2 )) :
	print("Second Number is less than First or Third Number")
elif((number_2 > number_1 ) or (number_3 > number_1 )) :
    print("First Number is less than Second or Third Number")
else:
    print("Condition not Satisfied...!")
    
To download raw file Click Here

Output : 2

Enter First value : 50
Enter Second Value : 20
Enter Third Value : 40

Logical OR Example
Second Number is less than First or Third Number