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

ps1 def pr(x): print'2' n=1 som=0 prod=1 ## odds= 2*n+1 cmpt=1 ## j=2 ## prim = True while cmpt < x: ## n=n+1 odds=2*n+1 j=2 prim= True while (j < odds) and (prim == True): if odds%j==0: prim = False else: j=j+1 if prim == True: print (n, odds,cmpt) som=som+odds prod=prod*odds print( som, prod) cmpt=cmpt+1

OpenStudy (anonymous):

Wow you need to use pastebin. also try to use more descriptive names it will make it easier to read. I think you are asking about the prime number exercise. Start with the premise that the number you are testing is prime and test for falseness. like this is_prime = True if the number is 1 then return false do a loop while the index is less then or equal to the square of the number to check if number % index == 0 then return false index = index + 1 return True So as you can see from the pseudo code that all you do is see if there is a remainder.

OpenStudy (anonymous):

my code work but thanks for your advices jimtuv

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!