Find elements

Python program: find smallest of three numbers using the function

Python program: find smallest of three numbers using the function

In this tutorial, we will discuss the concept of the Python program: find smallest of three numbers using the function

In this post, we will learn how to find the smallest number of three numbers using a user-defined function in the Python programming language

Python program: find smallest of three numbers

In my previous post, I have explained the various approaches to find the smallest number of among  three numbers in Python language

However, in this program, we embed the logic of this program in the function.

Here, I have explained how to find the smallest number from the given three numbers and how to embed this logic in the function.

Program 1

Find the greatest of three numbers using if elif statements

This program allows the user to enter three numbers and compare to select the smallest number using if-elif statements

num1=int(input("Enter the first number: "))
num2=int(input("Enter the second number: "))
num3=int(input("Enter the third number: "))

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();     #functio call

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

Enter the first number: 43
Enter the second number: 90
Enter the third number: 56
Smallest number is 43

Program 2

Find the smallest of three numbers using nested if statements

This program allows the user to enter three numbers and compare to select the smallest number using Nested if statements

 

num1=int(input("Enter the first number: "))
num2=int(input("Enter the second number: "))
num3=int(input("Enter the third number: "))

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();     #functio call

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

Enter the first number: 89
Enter the second number: 12
Enter the third number: 56
Smallest number is 12

 

Smiler post

C program to find the smallest  among three numbers using function 

Java code to find the smallest of three numbers using the method

C++ code to find the smallest of three numbers using the function

 

Suggested for you

Operator in Python language

If statements in Python language

function in Python language

 

 

 

Java program:find smallest of three numbers using method
C program:find smallest of three numbers using function
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago