Slider

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

Write a Python program that checks whether a given integer is even or odd. Python Code to check Even or Odd Number: Input: number = 7 Output: 7 isOdd
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.

0

No comments

Post a Comment

both, mystorymag

DON'T MISS

Tech News
© all rights reserved
made with by AlgoLesson
Table of Contents