Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Check If Input Is a Number
00:00
5 left

Check If Input Is a Number

MediumPython

Problem

Write a function that checks if the input is or is not a number.

Treat the input as a string and return True only for valid finite decimal or scientific-notation formats. Allow an optional leading sign, decimal values such as 12, -3.5, .8, and 7., and exponents such as 1e-4; reject whitespace, empty strings, malformed numbers, NaN, and infinity.

Input: one string value.

Output: a Boolean indicating whether value is a valid number.

Constraints

  • value is a string
  • 0 <= len(value) <= 1000
  • Only ASCII decimal digits, signs, decimal points, and exponent markers are relevant
  • Leading or trailing whitespace is invalid

Function Signature

def is_number(value):
Interviewer

Your question is Check If Input Is a Number. Start with the requirements in the Question tab.

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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.