anonymous
  • anonymous
I am currently using python version 2.5.4 and every time I try to use the "else" function it I get a syntax error. Why would I get this error? "SyntaxError: invalid syntax" Thanks in advance
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 :)
SOLVED
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.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
Can you write out an example?
anonymous
  • anonymous
ok here is an example: I did create the problem myself but in every problem I write else: I always get this same response: >>> limit = 1000 >>> counter = 1 >>> current_number = 1 >>> while counter < limit: is_prime = 1 current_number = current_number + 2 for i in range (2, current_number%i) == 0: is_prime = 0 break if is_prime != 0: counter = counter + 1 if counter == limit: print current_number, "is the 1000th prime number" else: SyntaxError: invalid syntax
anonymous
  • anonymous
The else function is colored in red to show that there is a syntax error there.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
Well, here the else: is tabbed incorrectly. It needs to be lined up with the if: if is_prime != 0: counter = counter + 1 if counter == limit: print current_number, "is the 1000th prime number" else: Let me know if that solved it.
anonymous
  • anonymous
yes, that was the problem thanks for the help.

Looking for something else?

Not the answer you are looking for? Search for more explanations.