Input two numbers and display the larger / smaller number in python

Input two numbers and display the larger / smaller number in Python. Today we are showing the code in python. This python project is useful for beginners, CBSE School Class 11 students Computer Science practical file and NIELIT O Level Programming and Problem Solving through Python (Module M3-R5).

If/else case in Python

In if case first the condition in the same line of if is evaluated if it is true then it is executed and else the commands after else is executed. So, This is evaluation method , plus executing method.

Objective : Input two numbers and display the larger / smaller number in Python.

Screenshot of the source code written it is very important to read every step

Program code Input two numbers and display the larger / smaller number in Python.

Python Program to find Largest of two Numbers using if-else statements

a = int(input(“Enter the first number: “)) #input first number
b = int(input(“Enter the second number: “)) #input second number
if(a >= b): #comparing
print(a, “is greater”)
else:
print(b, “is greater”)

Output of the program

We enter the first number : 56 and the second number :28 an then comparing it tells 56 is greater.

Testing is done .

Run the python program and enter the required data.

Source code of Program ->click here

Thanks for reading and learning about this program.

for more python programs -> click here

Hello World Program in Python

Input a welcome message and display it in Python

Display the larger / smaller number in Python.

Greatest of Three Numbers in Python using Nested if

Patterns using nested loop in Python

Program to Print Pattern in Python

Program to input the value of x and n and sum of series in Python

Python Program for Armstrong, Prefect Number, Palindrome

Program of Prime number by recursion in python

Prime Number Program in Python

Write a Program to Print Fibonacci Series in Python

LCM and GCD program in Python

Python program to count number of vowels in a string

Whether a String is Palindrome or not in Python

Bubble Sort Program in Python

Linear search in python using list

Program to read a text file in python

Python program to read a file line by line

Program to Count Vowels and Consonants in Python

Stack Program in Python

Queue Program in Python

Python Leap Year Program for Beginners

Python Program to Print Series and Addition

Binary Search Program in Python

Program to find sum of digits in python

Sum of numbers divisible by 3 and 5 in python

In this python program, we will take two numbers from user and display larger and smaller number in python, which can compare these two numbers and print larger and smaller number depending upon the user-entered input.

Also, we will discuss how to check equality of both number in python

Identify larger and smaller number in python

Let us see how we can compare and display larger and smaller number in python 

Program Logic:

  • Take two number as input from user using input method
  • Use if-else block to check which number is larger or smaller
  • Display larger and smaller number using print statement

Below is implementation code / Source code

# python program to find smaller and larger number #take two number from user num1 = int(input("Enter first number :")) num2 = int(input("Enter second number :")) if (num1 > num2): print(num1,"is larger than",num2) elif (num1 == num2): print(num1,"is equal to",num2) else : print(num1,"is smaller than",num2)

Explanation:

Here, we ask the user to enter first and second number of their choice. If the first number is greater than second number then it will display ” first number is larger than second number” else it will display “first number is smaller than second number”. If both numbers are equal then we it will display “first number is equal to second number”

Below is output of above code

>>> %Run 'smaller and larger number.py' Enter first number :23 Enter second number :34 23 is smaller than 34 >>> %Run 'smaller and larger number.py' Enter first number :34 Enter second number :33 34 is larger than 33 >>> %Run 'smaller and larger number.py' Enter first number :23 Enter second number :23 23 is equal to 23 >>>

Snapshot of executable code

Snapshot of python program to find smaller and larger number

Post navigation

How do you enter two numbers and display the larger smaller number?

# Python Program to input 2 numbers and display larger number.
#input first number..
num1=int(input("Enter First Number")).
#input Second number..
num2=int(input("Enter Second Number")).
#Check if first number is greater than second..
if (num1>num2):.
print("The Larger number is", num1).

How do you print the largest of two numbers in Python?

Source Code #Take two number from user to compare num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) #Compare both the number if num1 >= num2: if num1 == num2: print("Both numbers are equal. ") else: print("Fisrt number is greater than the second number.

How do I find the smallest number between two numbers in Python?

Python Number min() Method Python number method min() returns the smallest of its arguments: the value closest to negative infinity.

Chủ đề