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

Hi all, I need some help on ps1. After finding all odd number with a if statement, I don't know how to find the prime number. Any hint or advice would be appreciated. This is what I have so far: count = 2 #set to already include 1 and 2 as prime. num = 2 while count <=1000: num = num+1 if (num/2)*2!=num: #number is odd if it does not equal itself #print num count = count +1 # Use last to count if a prime is identified

OpenStudy (anonymous):

Hi! To find out if an odd number is a prime number, you need to run a loop that divides the odd by numbers from 2 to the odd itself minus 1! so you need to test this: if odd%divisor == 0: % is the modulo operator, it finds the remainder of division of one number by another, so if the result is zero then the odd number can be divided which means it's not a prime number! I hope this helps, and please excuse my English!

OpenStudy (anonymous):

And to make your current code slightly more efficient, why not start with num = 3 so that you can directly use num += 2 while being certain that all are odd?

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!
Latest Questions
YoungBlood: pfp wonu2019t let me switch
51 minutes ago 1 Reply 0 Medals
Austinsbabygirl4life: Do you think guys would survive on periods?
3 hours ago 22 Replies 2 Medals
alyviahwillis: if anyone has any questions feel free to DM me... I don't mind at all.
5 hours ago 0 Replies 0 Medals
Rosee5656: how do I level up!??!? >,
4 hours ago 14 Replies 4 Medals
Abby13915: I made an alpaca for my fashion club
9 hours ago 3 Replies 0 Medals
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!