Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Odd Number Function Logic

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Odd Number Function Logic. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

CG Advisor Network needs a small utility that classifies integer values for validation and routing logic. Implement a function that determines whether a given integer is odd.

Return True when the input has an odd value and False when it has an even value. The function must work for positive numbers, negative numbers, and zero. An integer is odd when dividing it by 2 leaves a remainder of 1 or -1, depending on the language's remainder behavior. In Python, number % 2 == 1 correctly identifies positive odd values, while number % 2 != 0 handles both positive and negative odd values consistently.

Formal Specification

  • Input: One integer number.
  • Output: A Boolean. Return True if number is odd; otherwise, return False.
  • Do not convert the number to a string or inspect its digits.

Constraints

  • -10^18 <= number <= 10^18
  • The input is always a valid Python integer
  • Use O(1) extra space

Function Signature

def is_odd(number):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output