Reputation: 1
def collatz_list(n):
int_list = [n]
int_index = n
while int_index >1 :
if int_index % 2 == 0:
int_index = int_index / 2
int_list = int_list.append(int_index)
else:
int_index = 3 * int_index 1
int_list = int_list.append(int_index)
return int_list
why when i run it ,it turns out to be NoneType
object has no attribute append
Upvotes: 0
Views: 74
Reputation: 54551
.append()
does not return the list, it returns None
. There's no need to assign back to int_list
anyway, just int_list.append(int_index)
would be fine.
Upvotes: 4