mardi 25 septembre 2018

How can I check if a number is in a range without using if statements? Python

I want the function to return true when a number falls within a set range, like [2,9) My first thought was to use a for loop like this

def in_an_interval(number): for i in range(2, 8): return print(bool(i==number))

but it only returned true for the first value, 2 Any thoughts? Thanks.

Aucun commentaire:

Enregistrer un commentaire