Python 3 : Lists advanced code challenges
the first code challenge/question says " Create a function called every_three_nums that has one parameter named start .

The function should return a list of every third number between 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."

i made the code:
def every_three_nums(start):
if start <= 100:
list1 = range[start,100,3]
list1 =
return list1


but it keeps giving an attribute error. can someone tell me how to correctly solve this?

Hello @xal1x, welcome to the forums!
Should a function (including the range function), be called with square brackets [] or parentheses ().


When you call a function, the function call looks like this:


Also, consider what the range function returns. Does it return a list?


hi! im still unable to get to the solution. ill appreciate it if u can provide the solution!

What is evident here is a fundamental misunderstanding of the range() object and the function that generates it.

range(start, stop, step)

We know that start is included in the range object but stop is not. What happens when the step is absent or positive and the start value is equal to or greater than the stop value? Answer: Nothing. There is no range object because it cannot be computed.

What does this mean for us? That we don’t need to test the value before applying the range. It will return an empty range object.

>>> len(range(100, 100, 3))

which would cast to an empty list. Study the function you are working with and study the problem to see when the two come together. Call me a fool but I always start my function body with a return and only give up when the expression cannot be found but through several steps.

1 Like

I hope this helps you. You were very close :smiley:

def every_three_nums(start):
if start <= 100:
lst1 = list(range(start, 101, 3))
return lst1

1 Like