 # How should I check if start is greater than 100?

I looked up range and used one of the examples i found. I’m pretty sure I have cheated here by setting my second value to 103 ; so i am interested in what the real solution should look like.

``````def every_three_nums(start):
if start > 100:
return []
else:
list_of_ints = list(range(start,103,3))
return list_of_ints

#Uncomment the line below when your function is done
print(every_three_nums(91))
``````
1 Like

I solved it with this function:

def every_three_nums(start):
return list(range(start, 101, 3))

#Uncomment the line below when your function is done
print(every_three_nums(91))

4 Likes

What is curious is that the correct answer/solution does not address the last function requirement.

`If`start`is greater than`100`, the function should return an empty list.`

``````def every_three_nums(start):
"""function should return a list of every third number between\n start and 100 (inclusive). For example, every_three_nums(91) should return the list [91, 94, 97, 100]. If start is greater than 100, the function should return an empty list."""
return list(range(start,101,3))
if start>100:
return []

print(every_three_nums(91))
print(every_three_nums(191))
``````
1 Like

Hi @pleabargain,

Your code doesn’t actually need this `if` block:

``````  if start>100:
return []
``````

If the `start` argument passed to the `range` constructor is equal to or greater than the `end` argument, and the `step` argument is positive, the result is an empty `range` object. In the current case, this occurs if the `start` value is greater than `100`.

That is sufficient to enable the first `return` statement within your `every_three_nums` function, by itself, to satisfy this requirement:

If `start` is greater than `100` , the function should return an empty list.

2 Likes

You can code the empty list but it’s not necessary. Using the range function will return an empty list if the number is above 100.
Try this and you will see:

def every_three_nums(start):
return list(range(start, 101, 3))

print(every_three_nums(101))

2 Likes

Hey, yes I know using the range() function it will return an empty list in case the number is higher that 100 but anyways, I don’t get why this code returns the list plus a “none” word.

``````def every_three_nums(start):
hundred = range(101)
if start > 100:
empty = []
return empty
elif start < 101:
hundred_range = range(start, 101, 3)
return print(list(hundred_range))
``````

Also the same if I do

``````def every_three_nums(start):
hundred = range(101)
if start < 100:
hundred_range = range(start, 101, 3)
return print(list(hundred_range))
else:
empty = []
return empty

``````

Is a longer solution but I wanted to understand anyway. I’m doing my research but if someone can give me a hint, I’ll appreciate that.