Categories: Uncategorized

Python code to check whether the number is odd or even using operators

Python code to check whether the number is odd or even using operators

In this tutorial, we will discuss Program to Python code to check whether the number is odd or even using operators

In this post, we are going to learn how to check whether te given number is odd or even number using operator in Python language

Code to check whether the number is odd or even

Code to Check whether the number is odd or even using modular operator

Program 1

num=int(input("Enter a number: "));
#the program asks input from the user
#the user entered value and it is stored in variable num
if(num%2)==0:
    print("{0} is Even number".format(num))
else:
    print("{0} is odd number".format(num))

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

Case 1

Enter a number: 354
354 is Even number

Case 2

Enter a number: 221
221 is odd number

 

Code to Check whether the number is odd or even using divisional operator

Program 2

num=int(input("Enter a number: "));
#the program asks input from the user
##the user entered value and it is stored in variable num
if(num/2)*2==num:
    print("{0} is Even number".format(num))
else:
    print("{0} is odd number".format(num))

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

Case 1

Enter a number: 67
67 is odd number

Case 2

Enter a number: 46
46 is even number

 

Code to Check whether the number is odd or even using bet wise operator

Program 3

num=int(input("Enter a number: "));
#the program asks input from the user
#the user entered value and it is stored in variable num
if((num & 1)==1):
    print("{0} is Odd number".format(num))
else:
    print("{0} is Even number".format(num))

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

Case 1

Enter a number: 778
778 is Even number

Case 2

Enter a number: 779
779 is Odd number

 

Suggested post

Function in Python language

Operator in Python language

Data type in Python

 

Similar post

Java Program to check whether the number is odd or even using operators

C Program to check whether the number is odd or even using operators

C++ Program to check whether the number is odd or even using operators

Python Program to check whether the number is odd or even using operators

Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.