-6

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
  • 1
    Please post the code that you have so far. I'd expect it to be a `for` loop over a `range()` with code to test each number for primeness. – mhawke Aug 22 '14 at 04:29
  • [What have you tried so far? What is not working about it?](https://stackoverflow.com/help/how-to-ask) Remember that **Stack Overflow is not a code-on-demand site**. You may want to [edit] your question to include further information – hlt Aug 22 '14 at 04:37
  • sorry bout that i was actually trying to study the codes from this post http://stackoverflow.com/questions/11619942/print-series-of-prime-numbers-in-python and posted my question at the same time so when i get back it will be more easier for me to understand it – Paul Van Doren Aug 22 '14 at 04:48
  • *"built in function"* - what you you expecting, `from laziness import two_to_100_with_primes_dashed`? – jonrsharpe Aug 22 '14 at 06:41

1 Answers1

0

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
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186