Prime solver giving composite numbers
up vote
0
down vote
favorite
primes=[2]
a=3
b=1
while True:
try:
if a%primes[b]==0:
a+=2
else:
b+=1
except IndexError:
primes.append(a)
print a
a+=2
b=1
I try to run this code to give me a list of primes, but it keeps spitting out numbers like 27,95, and other, larger composite numbers. The code runs and there are no syntax errors preventing it from doing so, but it will give me incorrect values, and I don't know why. Please let me know if you find any errors or if it is a problem with Python3.
python security primes mathematics
New contributor
Connor Sponsler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
primes=[2]
a=3
b=1
while True:
try:
if a%primes[b]==0:
a+=2
else:
b+=1
except IndexError:
primes.append(a)
print a
a+=2
b=1
I try to run this code to give me a list of primes, but it keeps spitting out numbers like 27,95, and other, larger composite numbers. The code runs and there are no syntax errors preventing it from doing so, but it will give me incorrect values, and I don't know why. Please let me know if you find any errors or if it is a problem with Python3.
python security primes mathematics
New contributor
Connor Sponsler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
primes=[2]
a=3
b=1
while True:
try:
if a%primes[b]==0:
a+=2
else:
b+=1
except IndexError:
primes.append(a)
print a
a+=2
b=1
I try to run this code to give me a list of primes, but it keeps spitting out numbers like 27,95, and other, larger composite numbers. The code runs and there are no syntax errors preventing it from doing so, but it will give me incorrect values, and I don't know why. Please let me know if you find any errors or if it is a problem with Python3.
python security primes mathematics
New contributor
Connor Sponsler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
primes=[2]
a=3
b=1
while True:
try:
if a%primes[b]==0:
a+=2
else:
b+=1
except IndexError:
primes.append(a)
print a
a+=2
b=1
I try to run this code to give me a list of primes, but it keeps spitting out numbers like 27,95, and other, larger composite numbers. The code runs and there are no syntax errors preventing it from doing so, but it will give me incorrect values, and I don't know why. Please let me know if you find any errors or if it is a problem with Python3.
python security primes mathematics
python security primes mathematics
New contributor
Connor Sponsler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Connor Sponsler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Connor Sponsler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 7 mins ago
Connor Sponsler
1
1
New contributor
Connor Sponsler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Connor Sponsler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Connor Sponsler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Connor Sponsler is a new contributor. Be nice, and check out our Code of Conduct.
Connor Sponsler is a new contributor. Be nice, and check out our Code of Conduct.
Connor Sponsler is a new contributor. Be nice, and check out our Code of Conduct.
Connor Sponsler is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f208259%2fprime-solver-giving-composite-numbers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown