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

HELP!! I'm stuck on ps1a. here's my code: http://dpaste.com/532527/ my reasoning behind the program is this: give prime the value 1. give even_number the value 2. set up a loop to repeat the process 999 times. add prime and even number to be new value for prime. check to see if prime can be evenly divided by numbers from 2 up to but not including prime. if it can be divided evenly by any number from 2 to but not including prime. keep adding 2 to even number and repeating until prime is not evenly divisible by 2 to but not including prime. after the loop is completed to obtain the prime make

OpenStudy (anonymous):

oops my reasoning got cut, here it is is full: give prime the value 1. give even_number the value 2. set up a loop to repeat the process 999 times. add prime and even number to be new value for prime. check to see if prime can be evenly divided by numbers from 2 up to but not including prime. if it can be divided evenly by any number from 2 to but not including prime. keep adding 2 to even number and repeating until prime is not evenly divisible by 2 to but not including prime. after the loop is completed to obtain the prime make even_number equal 2 again. print prime.

OpenStudy (anonymous):

my problem is that it won't let me divide by a tuple. any suggestions to get around this problem?

OpenStudy (anonymous):

You cannot divide by a tuple. You can divide by numbers in a tuple if you like, but tuples are containers, not numbers.

OpenStudy (anonymous):

You might want to try creating a list of primes since nonprimes cannot be divided evenly by primes.

OpenStudy (anonymous):

polpak: what i was trying to do was, as you said, divide by the numbers contained in the tuple. I just can't figure out how to do it

OpenStudy (anonymous):

for number in mytuple: if prime % number == 0: # prime is not prime.

OpenStudy (anonymous):

ooooooooooh tats how you do it thanks

OpenStudy (anonymous):

thats*

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!