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

problem set one, I have defined a function that shows odd numbers, I have defined a function that more or less determines if any given number is prime (but it spits out more than I really want) I would like a bit of advice how to solve this problem. I really feel on the cusp of solving it, but I'm very new to programming as a whole...

OpenStudy (anonymous):

# We'll see if a number is prime x = input('Give me a number ') if x == 0 and x == 1: print "Not prime" elif x == 2: print "prime" loam = () for n in range(2,x/2): if x%n == 0: loam += (n,) print "not prime" else: print "Prime sucka" #What I want to do next is test this tuple for any divisor other than 1, or x. I thought I might be able to use the "any() function" to try and clean it up. I have a decent idea of what I want it to do, but I am shaky at best in getting it worded right.

OpenStudy (anonymous):

Line 3: can x == 0 AND ==1 at the same time? You will never meet those conditions. It looks like you have the basic procedure down but why do you need to make a tuple? Is a number prime when it fails one test? (last line). A couple of terms that might help out with this problem: "or", "break", "continue".

OpenStudy (anonymous):

Fixed the union and turned it into a junction, The reason for the tuple is the assignment required returning the "1000th" prime, I would assume I would need a way to count quickly (like a list) for showing that. I'm tinkering around with your suggestions of break and continue.

OpenStudy (anonymous):

My picture of the test is asking if a number is divisible by any integer in the range between 2 and one half of the argument, would be a simple enough (even if longwinded) way of determining if a number is prime.

OpenStudy (anonymous):

whoops, turns out I'm retarded..I'm looking at this a little closer. Any other criticisms are welcome.

OpenStudy (anonymous):

ah, I did not look at what the assignment asked... so you need to add to a count when you determine that a number is prime. but you really don't need to make a list of all the numbers do you? I guess I don't get why you need the input from the user either. -while count<1000 (or for number in range 1-1000) -find out if number is prime -if number is not prime go on to next number -if number is prime count=count+1 -upon reaching 1000 print the current number.

OpenStudy (anonymous):

heheheh I constantly feel retarded when confronting something new.. good luck, hopefully I didn't say too much or too little.

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!