Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
Python list how to identify the given number is in the range Challenge Question

In python am having the list like

mylist  = [100  30  400 340, 230, 160,  25]

Given number is : 239

My aim is i have to identify this 239(given number) is in the range of or inbetween of the list each lement with +10 and - 10

Example i have to take the first value from list to verify that 243 is in between 100+10 and 100-10 Not that result false

same way have to compare to 30+10 , 30-10 then again 400+10 and 400-10 same like all

if any one of that inbetween the range i have to return as true if not match with any one then return false

How to do that

Here 239 in between 230+10 and 230-10 so no the result i will get as true

How to do this ??

Thank you in avance

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You may iterate on the element of your list, and for each test the expression value-10 < x and x < value+10 that can be written in once in python value-10 < x < value+10

def search_numbers(values, x):
    for value in values:
        if value - 10 < x < value + 10:
            print(f"Ok: {value}-10 < {x} < {value}+10")
            return True
    return False

mylist = [100, 30, 400, 340, 230, 160, 25]
print(search_numbers(mylist, 239))  # True
print(search_numbers(mylist, 243))  # False
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!