Even or Odd Checker

Tags: even, Function, odd

Write a Python function named is_even_or_odd that takes a single integer parameter and returns the string “Even” if the number is even, and “Odd” if it is odd.

Example 1:

Input: is_even_or_odd(5) 
Output: 'Odd'

Example 2:

Input: is_even_or_odd(12) 
Output: 'Even'

You can use the modulus operator to determine whether a number is even or odd. If the remainder is 0 when a number is divided by 2, it’s even. Otherwise, it’s odd.

def is_even_or_odd(num):
    return 'Even' if num % 2 == 0 else 'Odd'

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!