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

For problem set 1, question 1, a friend of mine sent me this: n = int(raw_input("Which Prime do you want? ")) counter = 1 prime = 3 total = n while (counter < total): divisor = prime/2 while (divisor > 1): if prime % divisor == 0: prime = prime + 2 divisor = prime / 2 else: divisor = divisor - 1 How does this actually work, I don't understand what is actually happening.

OpenStudy (anonymous):

Which part don't you understand. If you have Python installed on your computer then there is a help file which is really good. Start with the Tutorial that is in the help file - I have read parts of it many times. There is also an index tab (windows version anyway) that works great, you can use it to find info on specific statements, keywords and operators, etc.... the online docs are here: http://python.org/doc/ Have you watched the lectures?

OpenStudy (anonymous):

i have a doubt.... at the start of loop prime is 3, divisor =1 so it wont enter the next loop, further even if the counter increments its chking only for the prime number 3...

OpenStudy (anonymous):

Woops whole program isn't included.... here it is: n = int(raw_input("Which Prime do you want? ")) counter = 1 prime = 3 total = n while (counter < total): divisor = prime/2 while (divisor > 1): if prime % divisor == 0: prime = prime + 2 divisor = prime / 2 else: divisor = divisor - 1 counter = counter + 1 prime = prime + 2 print prime - 2

OpenStudy (anonymous):

5 have trouble wrapping my head around from "while (divisor > 1) ---> the end. (Assuming the total is 1000) 1. 3%1 == 0. 2. So prime is now 3+2=5. 3. The divisor is now 5/2=2. (integer division) 4. The count becomes 2 5. Then the prime becomes 7. 6. Then 7 is tested. 7. 7%2 != 0 8. So divisor -1 to equal 1 9. But does the count still go to 3, or does 7 get retested first?? and am I thinking this through correctly?

OpenStudy (anonymous):

OpenStudy (anonymous):

Thanks for all the help!

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
midnightriver46: Is anyone learning korean in here?
37 minutes ago 18 Replies 1 Medal
Gucchi: physics
21 hours ago 17 Replies 0 Medals
Gucchi: physics
1 day ago 10 Replies 0 Medals
gelphielvr: What's the difference between colonization and imperialism
20 hours ago 2 Replies 0 Medals
gelphielvr: I need tips on how to memorize long formulas does anyone have any
4 hours ago 4 Replies 0 Medals
gelphielvr: how do I find the valance electrons? no further info
4 hours ago 1 Reply 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!