Find elements

Python program to check a number is even or odd using function

Python program to check a number is even or odd using function

In this tutorial, we will discuss the Python program to check a number is even or odd using the function

In this program, we are going to learn about how to find the odd or even number from given number using function in the Python language.

 

First, we must understand what is even or odd?

What is Even or Odd

When the number is divided by 2 and the balance becomes zero and the above number is called as the even number – eg 2,4,6,8,10

and on the other sides when it is divided by 2 and balance becomes 1 they are called odd numbers or uneven numbers

 

In my previous post, I have explained the various ways to check whether the  number is even or odd in Python language

However, in this program, we embed the logic  of the check even or odd numbers program in the function

You can embed the logic of the  program to check even or odd numbers using any of the following approaches in the function

 

Once This program received the number it will check the given number either odd or even.

After receiving the input from the user, it is stored in the variable of num and then program divides the value of num by 2 and displays the output

Using modular operator

num=int(input("Enter a number for check odd or even: "))
def find_Evenodd(num):
    
    if(num%2==0):
        print(num," Is an even")
    else:
        print(num," is an odd")

find_Evenodd(num);//function call

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

Case 1

Enter a number for check odd or even: 349
349 is an odd

Case 2

Enter a number for check odd or even: 234
234 is an even

 

Using Bitwise operator

num=int(input("Enter a number for check odd or even: "))
def find_Evenodd(num)://function definition
    
    if(num&1==1):
        print(num, "is an odd number");
    else:
        print(num, "is an even number");

find_Evenodd(num);//function call

 

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

Case 1

Enter a number for check odd or even: 678
678 is an even number

Case 2

Enter a number for check odd or even: 765
765 is an odd number

 

Using the division operator

num=int(input("Enter a number for check odd or even: "))
def find_Evenodd(num)://function definition
    number=(num/2)*2
    if(number==num):
        print(num, "is a even number");
    else:
        print(num, "is a odd number");

find_Evenodd(num);//call the function

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

Case 1

Enter a number for check odd or even: 678
678 is a even number

Case 2

Enter a number for check odd or even: 987
987 is a odd number

 

Suggested for you

Python operator

python if else statements

Python function

 

Similar post

Python program to check whether a number odd or even

Python program to display even and odd number in the given range

Python code to display all even and odd numbers from 1 to n

Python code to display all even and odd numbers without if

 

Cpp program to check a number is even or odd using function
C function to check a number is even or odd
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.

View Comments

  • Write a function named collatz() that has one parameter named number. If number is even, then collatz() should print number // 2 and return this value. If number is odd, then collatz() should print and return 3 * number + 1.

    Then write a program that lets the user type in an integer and that keeps calling collatz() on that number until the function returns the value 1. (Amazingly enough, this sequence actually works for any integer—sooner or later, using this sequence, you’ll arrive at 1! Even mathematicians aren’t sure why. Your program is exploring what’s called the Collatz sequence, sometimes called “the simplest impossible math problem.”)

    Remember to convert the return value from input() to an integer with the int() function; otherwise, it will be a string value.

    Hint: An integer number is even if number % 2 == 0, and it’s odd if number % 2 == 1.

    The output of this program could look something like this:

    Enter number:
    3
    10
    5
    16
    8
    4
    2

  • print('Enter a number = ')
    x=input()
    print('entered number is=',x)
    n = x % 2
    k = 0
    if n > k :
    print(' Even ')
    else :
    print('Odd')

  • num = int(input('enter any number'))
    if num % 2:
    print('number is odd')
    else:
    print('number is even')

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

3 days ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago