Python Program to Check If a Number is Even or Odd.

Problem Statement: Write a Python program that checks whether a given integer is even or odd.

Example:
Input: number = 7
Output: 7 is Odd Number

Input: number = 10
Output: 10 is Even Number

Algorithm to Check Even or Odd Number.

STEP 1: Accept an integer as input from the user.
STEP 2: Use the modulo operator (%) to check if the number is divisible by 2.
  • If the result is 0, the number is even.
  • If the result is 1, the number is odd.
STEP 3: Print the result in output.

Python Code to check Even or Odd Numbers:
# Function to check even or odd
def check_even_odd(num):
    if num % 2 == 0:
        print(f"{num} is an even number.")
    else:
        print(f"{num} is an odd number.")

# Input
number = int(input("Enter an integer: "))

# Check and display result
check_even_odd(number)
Output:
Enter an integer: 12
12 is an even number.

Explanation:
In the above example, the check_even_odd function takes an integer as an argument and uses the modulo operator to check if it's divisible by 2. If the result is 0, it prints that the number is even; otherwise, it prints that the number is odd.

⚡ Please share your valuable feedback and suggestion in the comment section below or you can send us an email on our offical email id ✉ algolesson@gmail.com. You can also support our work by buying a cup of coffee ☕ for us.

Similar Posts

No comments:

Post a Comment


CLOSE ADS
CLOSE ADS