Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
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),

 one year ago
 one year 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), 
 one year ago
 one year ago

This Question is Open

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

paul99santosBest ResponseYou've already chosen the best response.0
My question is there any efficient or better source code than this?
 one year ago

VirPriscusBest ResponseYou've already chosen the best response.0
The 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.
 one year ago

paul99santosBest ResponseYou've already chosen the best response.0
Please post your source code to http://pastebin.com and copy/paste you're URL here.
 one year ago
See more questions >>>
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.