Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 7 Online
OpenStudy (anonymous):

Just joined no experience before so this exercise is doing my head in. Here is what I have and it just loops. Any help would be greatly appreciated. n=int (1) ##This will act as counter s=int (3) ## A number to get us started divs=int (2) ## Integers I will diving with. while n<5: ## to ensure I kill at 1000th prime while s%2 != 0: ## If its an even number it isnt prime while divs

OpenStudy (anonymous):

else: n= n+1 else: s = s+1 else: print s

OpenStudy (anonymous):

I'm not sure I understand what you're trying to do with the while ... else ... bits. I very rarely find a use case for while else, and in your specific case, I don't see how the innermost while loop will end since 3%n for every N in the natural numbers will never = 0. Try restricting yourself to only using else for if statements, and I think you'll have an easier time wrapping your brain around the task.

OpenStudy (anonymous):

I need the slap face smiley!! Thank you for your patience.

OpenStudy (anonymous):

Also using a pastebin site like dpaste.com can make it easier to see/edit your code to get help.

OpenStudy (anonymous):

You might want to also limit the numerator to odd numbers, and the divisors to a certain value less than the numerator, otherwise it will do the calculation up to the numerator -1, which is not needed. See this website for a good explanation. http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!