Table of Contents
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.
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
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
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
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)
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
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
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.