import math def check_for_age(ages , position , age): if len(ages) < 365: end = len(ages) - position else: end = 365 for j in range(position,end): if ages[j] == age: return True return False ages = [] for i in range(365): ages.append(15) for i in range(365): ages.append(16) for i in range(365): ages.append(17) for i in range(365): ages.append(18) for i in range(len(ages)): if check_for_age(ages,i,15) and check_for_age(ages,i,16) and check_for_age(ages,i,17) and check_for_age(ages,i,18): print i else: print i