Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 22 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
Breathless: Spooky witch but cute
4 hours ago 3 Replies 0 Medals
Arriyanalol: help
3 hours ago 10 Replies 2 Medals
Arriyanalol: @tinydinoUwU stop trying to find a argument u blad lil boy
1 day ago 5 Replies 3 Medals
Jaded012023: Please tell me what you all think of this song
6 hours ago 6 Replies 1 Medal
Arriyanalol: bro how
6 hours ago 2 Replies 3 Medals
Arriyanalol: cant wait for the new bluey movie in 2027
1 day ago 12 Replies 2 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!