Can someone explain what is wrong with this code that I get an error. I want to print the primes between 3 and 11. eventually I want to find the 1000th prime for pset01.
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
I know. what does this mean? what should I do to my code?
I still don't understand what you're trying to do. But this error message means you are trying to use the variable i before having given an initial value to it. You have to initialize i before the while loop.
But I said i = 3 -- first line.
Warning: I am *not* saying it's good programming style. I'm just explaining where does this error comes from.
Check this : http://www.saltycrane.com/blog/2008/01/python-variable-scope-notes/
You are using a variable named i inside a function, and another variable named i is defined in the global scope. If you want the interpreter to know that, inside the function, you are setting the global variable, you have to say it this way:
If you do that, you have another error, not related to the first one:
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Easy to fix by putting str() around i in the print statement.
After that the program seems to run: http://pastebin.com/VS8kYf56
Doesn't produce good results though.
sigh ... I know it somehow thinks 9 is prime.
Now this is my slightly better attempt using morfir's code -- explanation provided of course.
The only problem is, it refuses to find ith primes for i>100. otherwise, it works fine. heh -- the wonderful world of incompetent newbie programming...
please, can you explain what that error is.
How can I understand what these errors mean in general -- maybe if I can see visually the program running line by line...