Find Greater, Smaller or Equal number in Python

Comparison Operators in Python 3

In this program, we will learn about comparison operators in Python 3. 

Before finding the Greater, Smaller or Equal Number. We have knowledge about Comparison Operators. There are different comparison operations in python like other programming languages like Java, C/C++, etc. Those Operators are given below:

  • Equal to Operator (==): If the values of two operands are equal, then the condition becomes true.
  • Not Equal to Operator (!=): If the values of two operands are not equal, then the condition becomes true.
  • Greater than Operator (>): If the value of the left operand is greater than the value of the right operand, then the condition becomes true.
  • Greater than equal to (>=): If the value of the left operand is greater than or equal to the value of the right operand, then the condition becomes true.
  • Smaller than Operator (<): If the value of the left operand is less than the value of the right operand, then the condition becomes true.
  • Smaller than equal to (<=): If the value of the left operand is less than or equal to the value of the right operand, then the condition becomes true.

Find the Largest number smaller than or equal to number

def greater_smaller(num1,num2):

if num1>num2:

return "num_1 is greater"

elif num2>num1:

return "num_2 is greater"

return "both are equal"

#Here we take a input from user at a time.User have to enter number like 12,23 or 21,32. #Number will be seperated by comma. Or you can take input simple like num1=input() and #num2=input()
num1,num2=input("enter your num1&num2 values:").split(",")

print(greater_smaller(num1,num2))

Output:

C:\Users\Pramod\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Pramod/PycharmProjects/pythonProject/main.py
enter your num1&num2 values:12,23
num_2 is greater

Process finished with exit code 0

Recommended Post:

Get Salesforce Answers

Hi, I’m Pramod Kumar Yadav & a computer science Engineer with 3years of experience in Digital marketing. I’m self-motivated and love to do SEO.

Leave a Reply

%d bloggers like this: