Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Python program to Find Smallest of three numbers

Python program to Find Smallest of three numbers

Posted on March 29, 2021

Table of Contents

  • Python program to Find Smallest of three numbers
    • Code to find smallest numbers
      • Code to find smallest numbers  using if statements
      • Code to find smallest numbers  using if-else statements
      • Code to find smallest numbers  using if elif else statements
      • Code to find smallest numbers  using nested if statements
      • Code to find smallest numbers  using function

Python program to Find Smallest of three numbers

In this article, we will discuss the concept of Python program to Find Smallest of three numbers

In this post, we are going to learn how to write a program to find smallest number out of three numbers using different methods in Python program.

Code to find smallest numbers

Code to find smallest numbers  using if statements

In this code, we will find smallest number out of three numbers using if statements in Python language

Program 1

num1=int(input("Enter the first number: "))
num2=int(input("Enter the second number: "))
num3=int(input("Enter the third number: "))
#reading the input from the user 
if(num1<=num2 and num1<=num3):
   Smallest=num1
#checking num1 is small than num2 and num3
if(num2<=num1 and num2<=num3):
   Smallest=num2
#checking num2 is small than num1 and num3
if(num3<=num1 and num3<=num2):
    Smallest=num3
#checking num3 is small than num2 and num1
print("Smallest number is", Smallest)

When the above code is executed, it produces the following result

Enter the first number: 76
Enter the second number: 54
Enter the third number: 32
Smallest number is 32

 

Code to find smallest numbers  using if-else statements

In this code, we will find smallest number out of three numbers using if else statements in Python language

Program 2

num1=int(input("Enter the first number: "))
num2=int(input("Enter the second number: "))
num3=int(input("Enter the third number: "))
#reading the input from the user 
Smallest=num1 if num1<num2 else num2 if  num2<num3 else num3

print("Smallest number is", Smallest)

When the above code is executed, it produces the following result

Enter the first number: 65
Enter the second number: 43
Enter the third number: 21
Smallest number is 21

 

 

Code to find smallest numbers  using if elif else statements

In this code, we will find smallest number out of three numbers using if-elif-else statements in Python language

Program 3

num1=int(input("Enter the first number: "))
num2=int(input("Enter the second number: "))
num3=int(input("Enter the third number: "))
#reading the input from the user 
if(num1<=num2 and num1<=num3):
   Smallest=num1
#checking num1 is small than num2 and num3
elif(num2<=num1 and num2<=num3):
   Smallest=num2
#checking num2 is small than num1 and num3
else:
    Smallest=num3

print("Smallest number is", Smallest)

When the above code is executed, it produces the following result

Enter the first number: 78
Enter the second number: 34
Enter the third number: 12
Smallest number is 12

 

Program 4

#python program to find smallest of three numbers
num1=int(input("Enter the first number: "))
num2=int(input("Enter the second number: "))
num3=int(input("Enter the third number: "))
#reading the input from the user 
if(num1<=num2 and num1<=num3):
  print(num1," is the smallest")

elif(num2<=num1 and num2<=num3):
  print(num2," is the smallest")

else:
    print(num3," is the smallest")

When the above code is executed, it produces the following result

Enter the first number: 45
Enter the second number: 31
Enter the third number: 78
31 is the smallest

 

Code to find smallest numbers  using nested if statements

In this code, we will find smallest number out of three numbers using Nested if statements in Python language

Program 5

#python program to find smallest of three numbers using nested if
num1=int(input("Enter the first number: "))
num2=int(input("Enter the second number: "))
num3=int(input("Enter the third number: "))
#reading the input from the user

if(num1<=num2):
      if(num1<=num3):
            Smallest=num1
      else:
          Smallest=num3
else:
      if (num2<=num3):
        Smallest=num2
      else:
        Smallest=num3

        #display the smallest number
print("Smallest number is", Smallest)

When the above code is executed, it produces the following result

Enter the first number: 89
Enter the second number: 56
Enter the third number: 12
('Smallest number is', 12)

 

Code to find smallest numbers  using function

In this code, we will find smallest number out of three numbers using function in Python language

Program 6

#Python program to find smallest number of three
num1=int(input("Enter the first number: "))
num2=int(input("Enter the second number: "))
num3=int(input("Enter the third number: "))
#reading input from the user

def find_Smallest():  #function definition
    if(num1<=num2):
      if(num1<=num3):
            Smallest=num1
      else:
          Smallest=num3
    else:
      if (num2<=num3):
        Smallest=num2
      else:
        Smallest=num3

        #display the smallest number
    print("Smallest number is", Smallest)
find_Smallest();     #calling the function

When the above code is executed, it produces the following result

Enter the first number: 548
Enter the second number: 243
Enter the third number: 456
Smallest number is 243

 

Program 7

#Python program to find smallest number of three
num1=int(input("Enter the first number: "))
num2=int(input("Enter the second number: "))
num3=int(input("Enter the third number: "))
#reading the input from the user

def find_Smallest():  #function definition
    if(num1<=num2) and (num1<=num3):
        Smallest=num1
    elif(num2<=num1) and (num2<=num3):
        Smallest=num2
    else:
        Smallest=num3
    print("Smallest number is", Smallest)
find_Smallest();     #calling the function

When the above code is executed, it produces the following result

Enter the first number: 25
Enter the second number: 37
Enter the third number: 56
Smallest number is 25

 

Suggested post

Operator in Python language

Data types in Python language

If statements in Python language

Nested if statement in Python language

 

Similar post

Java program to find middle of three

C program to find middle of three

C++ program to find middle of three

Python program to find middle of three

 

Java program to Find largest of three numbers

C program to Find largest of three numbers

C++ program to Find largest of three numbers

Python program to Find largest of three numbers

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes