Advanced Python Code Challenges: Lists (Question 1)

Hi all,

I managed to get through the previous page but I’ve hit a brick wall with the above.

Here’s what I’ve got:

def every_three_nums(start):
  return range(start, 100, 3)
#Uncomment the line below when your function is done
print(every_three_nums(91))

Which just outputs:

range(91, 100, 3)

Where am I going wrong here? I’ve searched for some help on this forum but all the solutions seem to involve “while” which I don’t remember having learned yet. Have I missed a section? Or am I missing something obvious?

edit - the thing at the top says “Finally, if you get stuck, use our solution code!” but I can’t seem to find a way to access said code…

Hello, @byte7737224785, and welcome to the forums!

What specifically did the instructions ask for the function to return? Possibly a list? How can you make a list from a range?

1 Like

Hey, no you are right. We haven’t learned while loops or for loops yet, which would be the most logical way to solve this problem in my opinion. I solved it (finally) by writing two different functions. But then my friend solved it by writing a recursive function, and it was so beautiful and elegant that I almost cried. Not really - but… :slight_smile:

#Write your function here
def every_three_nums(start):
  if (start <= 100):
    return [start] + every_three_nums(start + 3)
  else:
    return []

print(every_three_nums(91))

The trick is that this:

[1] + [2] + [3]

is the same as this:

[1] + [2] + [3] + [] 

Kind of weird. I personally think this problem was obnoxious. It didn’t really do a good job of serving to teach the concept in an iterative way. It just served to make the already proficient programmer feel self satisfied. There’s… way enough of that in the world already.

Hi @byte7737224785 I just recently got to these challenges myself but to make this function return a list, you have to include the list command.

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

The trick here is to turn it into a list so that it returns the numbers between and by setting the end to 101, it will include 100 if needed. Hope this helped!