If statement

Python program to Find Smallest of three numbers

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

Karmehavannan

Recent Posts

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

11 months ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

11 months ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

11 months ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

11 months ago

Function/method to convert Celsius into Fahrenheit -Entered by user

Function/method to convert Celsius into Fahrenheit -Entered by user In this article, we will discuss…

11 months ago

Temperature conversion: Celsius into Fahrenheit using function or method

Temperature conversion: Celsius into Fahrenheit using a function or method In this article, we will…

11 months ago

This website uses cookies.