Check if a number is even or odd in python



Check if a number is even or odd

This program takes a number (num) and checks if it is even or odd using the modulo operator (%). If the remainder of num divided by 2 is 0, then it is even. Otherwise, it is odd.


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


Comments

Popular posts from this blog

Simple Python Program Code for Snake Game

Project 01: Python Code for Music Recommendation with Explanation

Iris Flowers Classification ML Project with Code