UPSC Exam  >  UPSC Questions  >  Write a function to determine whether a given... Start Learning for Free
Write a function to determine whether a given integer is even or odd. **Input:** An integer num (-10^9 ≤ num ≤ 10^9). **Output:** Return "Even" if the given number is even. Return "Odd" if the given number is odd. **Sample Input:** 4 **Sample Output:** Even?
Most Upvoted Answer
Write a function to determine whether a given integer is even or odd. ...
Approach:
To determine whether a given integer is even or odd, we can use the modulo operator (%). If the number is divisible by 2 with 0 remainder, then it is an even number. Otherwise, it is an odd number.

Algorithm:
- Check if the given number is divisible by 2.
- If the remainder is 0, the number is even.
- If the remainder is not 0, the number is odd.

Code:
Here is a simple Python function to determine whether a given integer is even or odd:
python
def even_or_odd(num):
if num % 2 == 0:
return "Even"
else:
return "Odd"

Sample Input:
4

Sample Output:
Even

Explanation:
- We pass the number 4 to the function `even_or_odd`.
- Since 4 is divisible by 2 with 0 remainder, the function returns "Even".
- Therefore, the output is "Even".
Explore Courses for UPSC exam

Top Courses for UPSC

Write a function to determine whether a given integer is even or odd. **Input:** An integer num (-10^9 ≤ num ≤ 10^9). **Output:** Return "Even" if the given number is even. Return "Odd" if the given number is odd. **Sample Input:** 4 **Sample Output:** Even?
Question Description
Write a function to determine whether a given integer is even or odd. **Input:** An integer num (-10^9 ≤ num ≤ 10^9). **Output:** Return "Even" if the given number is even. Return "Odd" if the given number is odd. **Sample Input:** 4 **Sample Output:** Even? for UPSC 2024 is part of UPSC preparation. The Question and answers have been prepared according to the UPSC exam syllabus. Information about Write a function to determine whether a given integer is even or odd. **Input:** An integer num (-10^9 ≤ num ≤ 10^9). **Output:** Return "Even" if the given number is even. Return "Odd" if the given number is odd. **Sample Input:** 4 **Sample Output:** Even? covers all topics & solutions for UPSC 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Write a function to determine whether a given integer is even or odd. **Input:** An integer num (-10^9 ≤ num ≤ 10^9). **Output:** Return "Even" if the given number is even. Return "Odd" if the given number is odd. **Sample Input:** 4 **Sample Output:** Even?.
Solutions for Write a function to determine whether a given integer is even or odd. **Input:** An integer num (-10^9 ≤ num ≤ 10^9). **Output:** Return "Even" if the given number is even. Return "Odd" if the given number is odd. **Sample Input:** 4 **Sample Output:** Even? in English & in Hindi are available as part of our courses for UPSC. Download more important topics, notes, lectures and mock test series for UPSC Exam by signing up for free.
Here you can find the meaning of Write a function to determine whether a given integer is even or odd. **Input:** An integer num (-10^9 ≤ num ≤ 10^9). **Output:** Return "Even" if the given number is even. Return "Odd" if the given number is odd. **Sample Input:** 4 **Sample Output:** Even? defined & explained in the simplest way possible. Besides giving the explanation of Write a function to determine whether a given integer is even or odd. **Input:** An integer num (-10^9 ≤ num ≤ 10^9). **Output:** Return "Even" if the given number is even. Return "Odd" if the given number is odd. **Sample Input:** 4 **Sample Output:** Even?, a detailed solution for Write a function to determine whether a given integer is even or odd. **Input:** An integer num (-10^9 ≤ num ≤ 10^9). **Output:** Return "Even" if the given number is even. Return "Odd" if the given number is odd. **Sample Input:** 4 **Sample Output:** Even? has been provided alongside types of Write a function to determine whether a given integer is even or odd. **Input:** An integer num (-10^9 ≤ num ≤ 10^9). **Output:** Return "Even" if the given number is even. Return "Odd" if the given number is odd. **Sample Input:** 4 **Sample Output:** Even? theory, EduRev gives you an ample number of questions to practice Write a function to determine whether a given integer is even or odd. **Input:** An integer num (-10^9 ≤ num ≤ 10^9). **Output:** Return "Even" if the given number is even. Return "Odd" if the given number is odd. **Sample Input:** 4 **Sample Output:** Even? tests, examples and also practice UPSC tests.
Explore Courses for UPSC exam

Top Courses for UPSC

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev