Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda