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)
4 Antworten
+ 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.
+ 2
But better do like this,
ages = [...]
for age in ages:
if age > 18 and age <25:
+ 1
if y_adult >18 and y_adult<25:
+ 1
@Shadoff ohh have to add the variable in again, thanks
@Ipang oohhh that's very interesting