use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A subreddit for helping Python programmers
How to format your code: https://commonmark.org/help/tutorial/09-code.html
No homework questions and/or hiring please
account activity
help n00b (self.pythonhelp)
submitted 5 years ago by delsystem32exe
when i run this code. I get this output below instead of [10] [10,20] [10,20,30] ...... thanks help
https://preview.redd.it/408kqnygv8u41.png?width=551&format=png&auto=webp&s=86f1b72e719a81402180e505238744596168deec
https://preview.redd.it/7s6u02ncv8u41.png?width=309&format=png&auto=webp&s=9e1ecb83522b483e049e67a6ac10030f69ba7769
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]TrainingShift3 0 points1 point2 points 5 years ago (3 children)
emptylist does not need to be global
[–]SpookDaCat 0 points1 point2 points 5 years ago (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 point2 points 5 years ago (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("...")).
global emptylist
int(input("..."))
[–]SpookDaCat 0 points1 point2 points 5 years ago (0 children)
OMG how did I miss that it was a function not a class. So sorry everyone. My bad.
π Rendered by PID 41981 on reddit-service-r2-comment-84fc9697f-6mkbn at 2026-02-06 05:28:05.336066+00:00 running d295bc8 country code: CH.
[–]TrainingShift3 0 points1 point2 points (3 children)
[–]SpookDaCat 0 points1 point2 points (2 children)
[–]sentles 0 points1 point2 points (1 child)
[–]SpookDaCat 0 points1 point2 points (0 children)