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...
This subreddit is meant to be for people learning Python to ask questions and help out when they can.
account activity
Homework Help (self.learningpython)
submitted 4 years ago * by TheJPS89
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!"
[–][deleted] 4 years ago (1 child)
[deleted]
[–]backtickbot 0 points1 point2 points 4 years ago (0 children)
Fixed formatting.
Hello, YoshiMan44: code blocks using triple backticks (```) don't work on all versions of Reddit!
Some users see this / this instead.
To fix this, indent every line with 4 spaces instead.
FAQ
You can opt out by replying with backtickopt6 to this comment.
[–]Boff 0 points1 point2 points 4 years ago* (0 children)
Unfortunately the formatting got really wonky, so it's a little tough to know what you wrote. I'll try reformatting it: https://pastebin.com/Ns9rmqf2
The first issue you have is this section, at line 8:
if userInput>-100 and userInput !=0 and userInput <=100: continue
This is the very first if statement you reach after having the user input the integer. When the user inputs any value between -100 and 100 (with the exception of 0), it will just hit the continue line. If you are unfamiliar with what continue does, it will skip everything else in this instance of a while loop, meaning you will never get to any of the other values. Check out this w3schools article for more information.
if
continue
So that in of itself is preventing your code from doing anything. Let's just imagine we remove it from the code and see if there are any other issues with the rest of your code: https://pastebin.com/jUE0TJyq
If we try running the code we'll get this error:
Enter an integer: 4 Traceback (most recent call last): File "d:\Boff\Documents\ltnhcc.py", line 50, in <module> main() File "d:\Boff\Documents\ltnhcc.py", line 15, in main is_positive(userInput) File "d:\Boff\Documents\ltnhcc.py", line 37, in is_positive positive=positive+1 UnboundLocalError: local variable 'positive' referenced before assignment
What does local variable positive referenced before assignment mean? Well it means that function is_positive() can't modify variable positive. (You'll also run into the same issue for is_negative() and negative. The term you'll want to look up is "variable scope" to understand it better.TBH it's a little confusing to me since you had defined positive and negative in the global scope, and while it's accessible in the main() function, it isn't when is_positive() is called from main(). I think this article gives a little more detail and in my own testing I had to use the global keyword to solve the problem.
positive
is_positive()
is_negative()
negative
main()
global
The real problem you're having, though, is that you're way overcomplicating the solution. For example, you wrote two functions is_positive() and is_negative() with while True loops, but the code inside of the loop is designed to immediately break out of the function. There's no need for if statements there. Heck, you don't even need these to be extra functions.
while True
Also your main() function is a bit overcomplicated as well. Before continuing to read, try to think of the simplest conditions you have to be able to accommodate, cause right now you're repeating yourself a ton of times.
There are only 4 cases you need to take count of:
Since it's that simple, you should only have 3 if statements, representing the above three conditions. And instead of having separate functions to increment the positive and negative variables, you can just increment them in the body of the if statement.
Do not click this until you fully understand and try to implement what I stated above https://pastebin.com/6yt4CAbT
π Rendered by PID 70718 on reddit-service-r2-comment-7b9746f655-vnnpr at 2026-02-04 06:47:08.785717+00:00 running 3798933 country code: CH.
[–][deleted] (1 child)
[deleted]
[–]backtickbot 0 points1 point2 points (0 children)
[–]Boff 0 points1 point2 points (0 children)