0

Python: How to find a range of numbers in a list?

Hi, how do you a range of numbers in a list? Tried using And but it is not working? age = [44, 32, 18, 13, 26, 22, 21] for young_adult in age: if young_adult >18 and <25: print(young_adult)

8th Dec 2020, 7:12 AM
Terry
Terry - avatar
4 Respuestas
+ 2
if young_adult in range( 18, 26 ): # code Remember, range includes lower bound but excludes upper bound, that's why ( 18, 26 ) => from 18 to 25.
8th Dec 2020, 7:18 AM
Ipang
+ 2
But better do like this, ages = [...] for age in ages: if age > 18 and age <25:
8th Dec 2020, 7:19 AM
Shadoff
Shadoff - avatar
+ 1
if y_adult >18 and y_adult<25:
8th Dec 2020, 7:17 AM
Shadoff
Shadoff - avatar
+ 1
@Shadoff ohh have to add the variable in again, thanks @Ipang oohhh that's very interesting
8th Dec 2020, 7:47 AM
Terry
Terry - avatar