Write A Python Script To Check Whether A Given Number Is Even Or Odd

In this article let's learn how to write a python script to check whether a given number is odd or even.  given an input to the python script the python script has to check whether  a number is completely divisible by 2 or not if it is divisible it's an even number.


Let's use the above method to check if the given number is even or odd.

 

Write A Python Script To Check Whether A Given Number Is Even Or Odd

 

 

Write A Python Script To Check Whether A Given Number Is Even Or Odd

Take a variable Named as number,  ask a user to enter an integer number using  input function call,  convert the given number into an integer using the type conversion.

number = int(input("Enter a Number : "))




Use the if statement to check if the number is completely divisible by 2 using the modulus operator,  check if the reminder is equal to zero then print the  even number,  else print the number is an odd number.

if number % 2 == 0:
   print(f"Number : {number} is Even Number")
else:
   print(f"Number : {number} is an Odd Number")




Complete Python program
=============================

number = int(input("Enter a Number : "))

if number % 2 == 0:
   print(f"Number : {number} is Even Number")
else:
   print(f"Number : {number} is an Odd Number")






Output
============
Enter a Number : 55
Number : 55 is an Odd Number




Output
=============
Enter a Number : 88
Number : 88 is Even Number



Output
============
Enter a Number : 9
Number : 9 is an Odd Number



Conclusion
================
Execute the above program by providing a random number to the python script,  note down the result.

Comment it down below if you have any suggestions to improve the above Python program


Post a Comment

0 Comments