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
Program for find middle number out of three in C

Python code to find middle numbers out of three

Posted on March 13, 2021March 13, 2021

Table of Contents

  • Python code to find middle numbers out of three numbers
    • Program to find middle numbers
      • Code to find middle numbers  out of three using variable initialization
      • Code to find middle numbers  out of three using user input
      • Code to find middle numbers  out of three using function
      • Code to find middle numbers  out of three using function with user input

Python code to find middle numbers out of three numbers

In this article, we will discuss the concept of Python code to find middle numbers out of three numbers

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

Program to find middle numbers

Code to find middle numbers  out of three using variable initialization

In this code, we will find middle number out of three numbers using variable  initialization in Python language

Program 1

#Python program to find middle number out of three number
num1=9821;
num2=3456
num3=1230
#Variable declaration and initilaization

if(num2>num1 and num1>num3 or num3>num1 and num1>num2):
    print(num1, "is a middle number")
    #check and display whether the num1 is middle

if(num1>num2 and num2>num3 or num3>num2 and num2>num1):
    print(num2, "is a middle number")
    #check and display whether the num2 is middle

if(num1>num3 and num3>num2 or num2>num3 and num3>num1):
    print(num3, "is a middle number")
    #check and display whether the num3 is middle

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

3456 is a middle number

 

 

Code to find middle numbers  out of three using user input

In this code, we will find middle number out of three numbers using input from the user in Python language

Program 2

num1=int(input("Input first number: "))
#Takes input from user for num1
num2=int(input("Input second number: "))
#Takes input from user for num2
num3=int(input("Input tird number: "))
#Takes input from user for num3

if(num2>num1 and num1>num3 or num3>num1 and num1>num2):
    print(num1, "is a middle number")
    #check and display whether the num1 is middle

if(num1>num2 and num2>num3 or num3>num2 and num2>num1):
    print(num2, "is a middle number")
    #check and display whether the num2 is middle

if(num1>num3 and num3>num2 or num2>num3 and num3>num1):
    print(num3, "is a middle number")
    #check and display whether the num3 is middle

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

Input first number: 132
Input second number: 768
Input tird number: 543
543 is a middle number

 

Code to find middle numbers  out of three using function

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

Program 3

#Python program to find middle number among three
num1=5432
num2=9876
num3=6745

def middleNum():#function definition
    middle=0;
    if(num1>num2):
        if(num2>num3):
           middle=num2;
    
        elif(num3>num1):
           middle=num1;
    
        else:
            middle=num3;

    else:

        if(num2<num3):
            middle=num2;
    
        elif(num3<num1):
            middle=num1;
    
        else:
            middle=num3;
    
    print("middle number is",middle);
middleNum();#Calling the function

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

middle number is 6745

 

 

 

Code to find middle numbers  out of three using function with user input

In this Program, we will find middle number out of three numbers using function with user input in Python language

Program 4

#Python program to find middle number among three
num1=int(input("Enter the first number: "))
#get input from the user for first number
num2=int(input("Enter the second number: "))
#get input from the user for second number
num3=int(input("Enter the third number: "))
#get input from the user for third number

def middleNum():#function definition
    middle=0;
    if(num1>num2):
        if(num2>num3):
           middle=num2;
    
        elif(num3>num1):
           middle=num1;
    
        else:
            middle=num3;

    else:

        if(num2<num3):
            middle=num2;
    
        elif(num3<num1):
            middle=num1;
    
        else:
            middle=num3;
    
    print("middle number is",middle);
middleNum();#Calling the function

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

Enter the first number: 432
Enter the second number: 321
Enter the third number: 654
middle number is 432

 

Suggested for you

Operator in Python Language

if elif in Python language

Nested if in Python Language

Data type in Python language

 

Similar post

C++ code to find middle numbers out of three numbers

C code to find middle numbers out of three numbers

Java code to find middle numbers out of three numbers

Python code to find middle numbers out 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