MIT 6.00 Intro Computer Science (OCW) OpenStudy (anonymous):

ps1: I am absolutely, utterly, totally lost... Please just provide hints and not answers. I had trouble learning Java too. import math x = raw_input("Please enter a number ") def prime(x): if x < 2: return False if x%2 == 0: return False if x%3 == 0: return False if x%5 == 0: return False else: return True prime (x+2) OpenStudy (anonymous): OpenStudy (anonymous):

one just simple hint: prime numbers are not dividable exactly except for only two numbers-prime number itself and 1. it means it is not exactly dividable with any number lower than it but for 1.i recommend [while loop] with several [if] condition OpenStudy (anonymous):

first suggestion is throw away your code entirely. write out what you are trying to do in pseudo-code. for example, if the assignment were to write a program that adds any two numbers provided as input, your pseudo-code would look like this: retrieve as input two numbers add the two numbers print the result Suppose the example were slightly more complicated. If the problem was accept two integers as input and determine if the sum is even or odd. The pseudo-code might look like this: retrieve as input two integers add the two numbers if the sum is even, print "even" else print "odd" I encourage you to first write out the program in pseudo-code as a series of steps, then translate it into code. OpenStudy (anonymous):

I found an incredibly helpful post by Peter Otten here: http://groups.google.com/group/comp.lang.python/browse_thread/thread/f6f44b646af5b09e?pli=1 He actually explained each item you needed to figure out. Now my only question, how do I alter the code so I can enter a number and it will give me that prime. Like if I wanted to know the 30th prime or the 1000th, rather than have the code just print out the 1000th. import math def isprime(candidate): return candidate != 42 def all_natural_numbers(): i = 1 while True: yield i i = i + 1 def all_prime_numbers(): for i in all_natural_numbers(): if isprime(i): yield i i = 1 for p in all_prime_numbers(): if i == 1000: print p break i = i + 1 OpenStudy (anonymous):

When I look at the code above it appears convoluted. Some of it makes no sense whatsoever. If you are not going to write out what you are trying to achieve in pseudo-code, then work on a simple problem first and post the code for that. See if you can write the following program: The program accept as input some integer, and determines whether the number is prime or not. The program output should something like this: -------- What number would you like me to test for primality? 5 True -------- What number would you like me to test for primality? 121 False etc. I wouldn't tackle the 1000th prime problem until you are able to complete this program first. OpenStudy (anonymous):

I've googled it and this: for x in range(2,int(n**0.5)+1): Makes absolutely no sense to me. OpenStudy (anonymous):

This whas the code it came from: def isPrime(n): if n == 1: return 0 else: for x in range(2,int(n**0.5)+1): if n%x == 0: return 0 return 1 OpenStudy (anonymous):

This doesn't work and it's all I can figure out: defPrime(x): if x%2 == 0: return False if x%3 == 0: return False if x%5 == 0: return False else: return True OpenStudy (anonymous):

Forget Google. Forget Coding. Think. If I give you a number, how would determine whether it's prime or composite? What are the steps? Write that down. For example, if I give you the number '17', how would YOU determine whether it's prime or not? OpenStudy (anonymous):

If it's divisible by 2 and/or 3 and/or 5 then it's not a prime. OpenStudy (anonymous):

Good. Your answer is *not* correct. But this is a step forward. What you say is partially true. Indeed, if a number is divisible by 2 or 3 or 5 then it is not prime. But a number is not prime if it is divisible by *any* number other than itself. So, for example the number 49 is not prime. Why? Because it is divisible by 7. If we were to use your test (is it divisible by 2,3, or 5) then we would conclude that 49 is prime, which it is not. OpenStudy (anonymous):

So can you try again? How would test to see if 17 is or is not a prime number? And why? OpenStudy (anonymous):

malpaso...you are trying really hard to give instruction...clap clap clap OpenStudy (anonymous):

I recommend you check out lecture 4, near the end. The professor's discussion on the Fibonacci sequence is of particular use in this area. You'll want a 'recursive' answer. As a side note, trying to solve for big numbers might crash your program- you'll actually see an example of that when the Prof. tries to enter '36' into his code. But, in theory, it's sound. OpenStudy (anonymous):

definition of prime number===can't be exactly dividable except 1and prime number itself OpenStudy (anonymous):

more precisely... if x is a prime number let's say y=x-1 then x%y is not 0 x%(y-1) is not 0 x%(y-2) is not 0 ... x%1 is only 0 (assumed y is bigger than 2) i.e) 3%2=1 but 3%1=0 OpenStudy (anonymous):

I've been stuck on this problem for a while too. Please check my logic: I started out with the numbers 2, 3, 5, 7. If the candidate_value was any of those, the script should instantly return as a prime number, and move onto the next. I then tried to check if any numbers divided by 2, 3, 5, 7 left any remainders. If so, it is also a prime number. OpenStudy (anonymous):

please! prime number definition is not "is it dividable by 2,3,5,7 or not?"! prime number asks you is it exactly dividable with 1 and prime number itself! don't you think 11 is also prime number? OpenStudy (anonymous):

i hope you study mathematics OpenStudy (anonymous):

student47, that's the opposite of what i said. 11 would be prime since it isn't dividable by 2,3,5, or 7 OpenStudy (anonymous):

i hope you could read more carefully henceforth. OpenStudy (anonymous):

i want to ask you ' how about 121, is it prime number?' OpenStudy (anonymous):

Heh- I was just looking for one myself. OpenStudy (anonymous):

oh wow, didn't think of that. thanks OpenStudy (anonymous):

sorry, just a little frustrated. OpenStudy (anonymous):

Does anyone know of a way I can send andi a hint about what he needs to be looking for without giving it away to tigger? Like a pm system? OpenStudy (anonymous):

Put something on student47s post. OpenStudy (anonymous):

The question the helped me was, “what "happens" when a number that is prime is divided by a number that is not itself.” and “how is this different than what happen when a non-prime is divided by itself?” Merely saying it is/is not divisible by x doesn't help with the process. I'm stuck on the second part, though. i don't understant the log e**n question OpenStudy (anonymous):

ushwia, can you post your log question as a separate question? that way more people will see it. otherwise it will stay buried in this thread. thanks. OpenStudy (anonymous):

I am having the same problem with this one, here is how i figured out that a number is prime. x = 8 if x % 2 != 0 and x % 1 == 0: x% x print x, " is prime" else: print x, " is not prime" now that i can determine that the number is prime, How do i tell it find the 100th prime and print it, I know it involes using a loop.. thats where i am at..

Latest Questions shalong: What was John Calhounu2019s major objection to high tariffs?
5 minutes ago 0 Replies 0 Medals hayhay6: Give an example of an equation of a line with an undefined slope. What type of li
40 minutes ago 1 Reply 0 Medals hayhay6: What is the equation of a line that passes through the point (5, -3) and has a sl
50 minutes ago 1 Reply 0 Medals piperkoebel: Does anyone know the coordinates of two points on the line y = u22122?
53 minutes ago 1 Reply 0 Medals lolokrat: anyone good with microeconomics that can help me find out where i went wrong on m
12 hours ago 0 Replies 0 Medals AsleepAndUnafraid21: URGENT PLZ HELP NOW Part C: Find the distance from B to E and from P to E. Show your work.
13 hours ago 49 Replies 5 Medals Kachirikutoka: How many solutions does the following equation have? |3x + 12| = 18 a No solution
18 hours ago 1 Reply 1 Medal AsleepAndUnafraid21: In the figure below, segment DE is parallel to segment BC and segment EF is parallel to AB: The figure shows triangle ABC with segments DE and DF.
15 hours ago 11 Replies 0 Medals AsleepAndUnafraid21: In the figure below, segment DE is parallel to segment BC and segment EF is parallel to AB: The figure shows triangle ABC with segments DE and DF.
18 hours ago 1 Reply 0 Medals lakeawilliams: What is the solution to StartFraction 5 over 6 EndFraction x minus one-third grea
20 hours ago 1 Reply 0 Medals