Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

I am STUMPED!!! I have read through my code and I can't see why it is missing some numbers as even and calling them primes. If any good samaritans out there could review this I would be appreciative. print "Thank you for using Greg's Prime Number Generator" ## primes = raw_input ('How many Prime Numbers do you need?: ') primes = 20 count = 0 n = 2 while count < primes: if n < 3: ## This denotes 2 as a prime count = count + 1 print count, n n = n + 1 else: hid = int (n**(0.5)) + 1 # Resets var (hid) to sqrt of n (+ 1)

MIT 6.00 Intro Computer Science (OCW)
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Join Brainly to access

this expert answer

SEE EXPERT ANSWER

To see the expert answer you'll need to create a free account at Brainly

I got cut off... print "Thank you for using Greg's Prime Number Generator" ## primes = raw_input ('How many Prime Numbers do you need?: ') primes = 20 count = 0 n = 2 while count < primes: if n < 3: ## This denotes 2 as a prime count = count + 1 print count, n n = n + 1 else: hid = int (n**(0.5)) + 1 # Resets var (hid) to sqrt of n (+ 1) if (n >=3) and (n % 2) == 0: print "num:", n,'Not Prime Even' n = n + 1 else: while hid > 1: if n % hid != 0: print "num:", n, "trying denominator:", hid hid = hid - 1 else: print "num:", n, 'Not Prime Odd' n = n + 1 hid = 0 else: count = count + 1 print count, n n = n + 1 else: print 'End of List'
There's a minor mistake in the second while loop: after finding an odd number it always takes two steps instead of one (n is incremented both inside and outside the loopl). I'm still thinking about an elegant solution, though, but I guess you can take it from here ;)
please use a code pasting site: - http://dpaste.com - http://pastebin.com - http://www.repl.it/ - http://pastie.org - http://codepad.org - http://ideone.com paste your code there and post the link here. select Python syntax highlighting when u paste.

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

maybe try writing out the steps you need to take to accomplish the task first - then turn that 'pseudocode' into code; revising the ''pseudocode' as you progress.
As the professor said in class, most of our time as programmers is spent debugging. So, I've found debugging skills very useful. They're prevented me from breaking stuff in my room many times. You do have print statements in your code, but try to make them more useful by adding explanations like what you're expecting to see. An example from your own code: while count < primes: print 'entering the while loop...' if n < 3: print 'entering if n<3...' ## This denotes 2 as a prime count = count + 1 print 'the number of prime numbers found is "', count, '"', 'and the number just analyzed was "', n, '"' n = n + 1 As I said before, I prefer showing you how to debug rather than debug the code itself. It's the old "show you how to fish vs. give you a fish" thing. Learned it from my father.

Not the answer you are looking for?

Search for more explanations.

Ask your own question