what I'm trying to do is to print the numbers 2-100
and mark the prime numbers with -
So, this should be the output:
2-
3-
4
5-
6
7-
8
9
10
.
.
.
100
what I'm trying to do is to print the numbers 2-100
and mark the prime numbers with -
So, this should be the output:
2-
3-
4
5-
6
7-
8
9
10
.
.
.
100
Try this code:
primes = []
for candidate in range(2, 101):
can_be_prime = True
for prime in primes:
if candidate % prime == 0:
can_be_prime = False
break
if can_be_prime:
primes.append(candidate)
print "%d-" % candidate
else:
print candidate