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

problem 1_1 how can i define the divisor so i can divide every number by every integer less than than the number but higher than 2?

OpenStudy (anonymous):

for integer in range(3,highNum/2): highNum/integer integer += 1 if i remember correctly... obviously add more to that and expand but yeah. I'm not sure if integer += 1 is necessary, someone better than me at this should come to the rescue should I be wrong

OpenStudy (anonymous):

problem is: i can't divide a number by a list

OpenStudy (anonymous):

why do you have a list? the range will include all numbers starting with 3 up to the highest number (your prime) divided by 2 (saves time, no need to check higher than that)

OpenStudy (anonymous):

ok instead of creating a list or something, keeping in mind my fastest prime finding code uses a list and a for loop, and not much else try something like x = -10 while x < 10: x = x +1 print x use while statements to do the same snippet of code over and over again, then use if, elif, and else statements to check if your number is prime, if you have a divisor so large you can stop checking, and if neither is true, change your divisor

OpenStudy (jhonny111s):

for i in range(2, number) // 2,3,4,5.. cont=0 while number!=0 if i%(number)==0 // 5 in this case cont+=1 // if cont is exactly 2, for examp 5/1 and 5/5 is prime number-=1 if cont==2 print is a idea

OpenStudy (anonymous):

This it what I would use: for i in range(2, int(math.sqrt(n))): ... then you can check to see if n%i == 0

OpenStudy (anonymous):

edit: for i in range(2, int(math.sqrt(n)) +1): ... forgot the +1, my bad.

OpenStudy (anonymous):

ok that is a lot of stuff to dump on someone with no previous knowledge, I mean sure I would use a for loop and lists, but I had no idea how to handle that for problem set 1, your introducing so many concepts with those statements, Izze just has to trust the lines you tell him/her to use and have no idea what he is programming, missing the point of trying to learn a new skill for i in range(2, int(math.sqrt(n)) +1): for statement range() function how python reads end points. eg: [1:3] importing math changing the type of a variable iteration and iteratable variables give her two or three basic words to deal with, some basic math and let her figure it out nothing fancy yet

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!