A community for students.
Here's the question you clicked on:
 0 viewing
paul99santos
 3 years ago
Assignment #1 Computing Prime Numbers
Hi, I made a program from Assignment #1 Computing Primes Number, I don't know if there is any better program than this? Source code>
http://pastebin.com/91Y5WEnL
The Source Code:

for candiPrimes in range(2,410): #Test Primes Numbers from 2 to 410
divisor = 1
NumOfReTimes = 0 #Count how many remainder 0 will show up
while (divisor<=candiPrimes): '''Analogy: Numbers start from 2 / N times if two remainder 0 will show up and the number is Prime'''
if candiPrimes % divisor == 0:
NumOfReTimes += 1
divisor += 1
if NumOfReTimes == 2: #test if two remainder 0 did show up
print ' ' + str(candiPrimes),

paul99santos
 3 years ago
Assignment #1 Computing Prime Numbers Hi, I made a program from Assignment #1 Computing Primes Number, I don't know if there is any better program than this? Source code> http://pastebin.com/91Y5WEnL The Source Code:  for candiPrimes in range(2,410): #Test Primes Numbers from 2 to 410 divisor = 1 NumOfReTimes = 0 #Count how many remainder 0 will show up while (divisor<=candiPrimes): '''Analogy: Numbers start from 2 / N times if two remainder 0 will show up and the number is Prime''' if candiPrimes % divisor == 0: NumOfReTimes += 1 divisor += 1 if NumOfReTimes == 2: #test if two remainder 0 did show up print ' ' + str(candiPrimes), 

This Question is Open

VirPriscus
 3 years ago
Best ResponseYou've already chosen the best response.0I've run it, and it does what it's supposed to, namely, produce prime numbers less than 410.

paul99santos
 3 years ago
Best ResponseYou've already chosen the best response.0My question is there any efficient or better source code than this?

VirPriscus
 3 years ago
Best ResponseYou've already chosen the best response.0The only real improvement I can think of is that you don't need divisor to come all the way up to candiPrime. You only really need to go up to the sqrt of candiPrime.

paul99santos
 3 years ago
Best ResponseYou've already chosen the best response.0Please post your source code to http://pastebin.com and copy/paste you're URL here.
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.