I am creating a function that 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]. Initially, I tried the following:
def every_three_nums(start):
list = []
a = 0
if start > 100:
return list
else:
a = range(start, 101, 3)
print(list(a))
print(every_three_nums(91))
And I get TypeError: 'list' object is not callable.
The same happens if I use
print(list(range(91, 101, 3)))
within the function. Despite this working outside the function.
I don't quite understand the rationale. Could you help me with this?
Eventually, I solved with:
def every_three_nums(start):
list = []
a = 0
if start > 100:
return list
else:
for i in range(start, 101, 3):
list.append(i)
return list
print(every_three_nums(91))