Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65239

Re:Python prime numbers

From Dave Angel <davea@davea.name>
Subject Re:Python prime numbers
Date 2014-02-01 16:59 -0500
Organization news.gmane.org
References <158634a8-3c20-4e04-bc2a-a562c7270a3b@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.6290.1391291803.18130.python-list@python.org> (permalink)

Show all headers | View raw


 Panagiotis Anastasiou <panast24@gmail.com> Wrote in message:
> Hi i'm new in programming and in python and i have an assignment that i cant complete. I have to Write a Python program to compute and print the first 200 prime numbers. The output must be formatted with a title and the prime numbers must be printed in 5 properly aligned columns . I have used this code so far :
> 
> numprimes = raw_input('Prime Numbers  ')
> count = 0
> potentialprime = 2
> 
> def primetest(potentialprime):
>     divisor = 2
>     while divisor <= potentialprime:
>         if potentialprime == 2:
>             return True
>         elif potentialprime % divisor == 0:
>             return False
>             break
>         while potentialprime % divisor != 0:
>             if potentialprime - divisor > 1:
>                 divisor += 1
>             else:
>                 return True
> 
> while count < int(numprimes):
>     if primetest(potentialprime) == True:
>         print potentialprime
>         count += 1
>         potentialprime += 1
>     else:
>         potentialprime += 1
> 
> but i get the result in a single column . How can i get it in 5 rows? Can someone help please
> 


-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python prime numbers Panagiotis Anastasiou <panast24@gmail.com> - 2014-02-01 07:33 -0800
  Re: Python prime numbers Larry Martell <larry.martell@gmail.com> - 2014-02-01 10:50 -0500
  Re:Python prime numbers Dave Angel <davea@davea.name> - 2014-02-01 16:59 -0500
  Re:Python prime numbers Dave Angel <davea@davea.name> - 2014-02-01 17:07 -0500
  Re: Python prime numbers Wiktor <look@signature.invalid> - 2014-02-02 00:34 +0100

csiph-web