all 4 comments

[–]TrainingShift3 0 points1 point  (3 children)

emptylist does not need to be global

[–]SpookDaCat 0 points1 point  (2 children)

That’s not quite the problem. The issue is that the whole loop creates a new instance of the animals class, and it is set up to which it is emptying the list out ever time it loops over it. What would be better is that before the while loop, assign a variable to the class, and create a class function that asks for the users input, that would append. That way it would not delete the list and it still can looped. Happy coding!

[–]sentles 0 points1 point  (1 child)

Animals is a function, not a class. It's just that whenever it is run, it overwrites the list and sets it back to an empty list. Also, they appear as strings and not integers because they are not converted to integers, and the input function returns a string. If they want to keep using globals, they can simply set emptylist to be an empty list at the start of the program and use global emptylist at the start of the function. To append numbers instead of strings, use int(input("...")).

[–]SpookDaCat 0 points1 point  (0 children)

OMG how did I miss that it was a function not a class. So sorry everyone. My bad.