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
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
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
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
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
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…
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')
i hate this but this is like this
FUK U MY EMAIL shafeenhossain45@gmail.com
i hate this dude shafeen mf raided my discord server fuk yalll i have grabbed his email with my token from the code i made from python :(