Python Programming :Odd or Even

Example

Input 
enter the number 5
Output
The number is odd

Required to Know

Use of Variables, Use of different operators like assignment or arithmetic operators, Use of functions like print(), and input(), Use of If-else, and Use of Data types.

Steps

  • Take the number as an input from the user.

  • Check if the number is divisible by 2 or not. If it is divisible print even. Otherwise, print odd.

Condition

if(num%2==0):
    print("even")
else:
    print("odd")

Program

# This code asks the user to enter a number and then prints whether it is even or odd.
num = int(input("Enter a number: "))
# This if-else statement checks if the number is even or odd.
if num % 2 == 0:
    # The number is even.
    print("The number is even")
else:
    # The number is odd.
    print("The number is odd")