Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'elif': 0.05; 'output': 0.05; 'subject:Python': 0.06; 'assignment': 0.07; 'column': 0.07; 'suppress': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'columns': 0.16; 'comma': 0.16; 'compute': 0.16; 'formatted': 0.16; 'true:': 0.16; 'wrote:': 0.18; '<': 0.19; 'pfxlen:0': 0.19; 'properly': 0.19; 'programming': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; '>': 0.26; 'header:In- Reply-To:1': 0.27; 'statement': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'aligned': 0.31; 'subject:numbers': 0.31; 'but': 0.35; 'received:google.com': 0.35; 'complete.': 0.36; 'false': 0.36; 'skip:p 20': 0.39; 'how': 0.40; 'break': 0.61; 'new': 0.61; 'numbers': 0.61; 'first': 0.61; 'to:addr:gmail.com': 0.65; 'prime': 0.74; '2014,': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=TMCRRa46qW7v/Mmmb07gGkJery8d8o7rJWP4cmLuDoo=; b=SqJ8fyhj5XLnEJTeLc7/oEuPf1P02vsjDzdjzyUm5JLy6fbESDuK9wIpVShJcej57/ HpesDrC23gZOlNk89qe+5Oj1mjYRvxLkV8hLdz99G52Xc1BvwvtwjpDX6/iY3F0caxj9 bfdj4cO3WnvnEISorRUTLZOXA/0V8qKl9UvqG2HOzaP+XCrheXCU1C5SbGz/klp+FrFD TgEox7g1HFMhlRJ2F9vS9NA6QcvLKkyG+XhNcKBEc3zTrbh5t2zkJyNOSYuiCoNXSE+k 3+qkp8Y9AEa9C7hieJ60D/hd9zZJcV4eScZL7+a8XOOQninEfbdbkA1YxlSlsjdVT4vy NJbQ== MIME-Version: 1.0 X-Received: by 10.140.50.131 with SMTP id s3mr4166376qga.12.1391269853110; Sat, 01 Feb 2014 07:50:53 -0800 (PST) In-Reply-To: <158634a8-3c20-4e04-bc2a-a562c7270a3b@googlegroups.com> References: <158634a8-3c20-4e04-bc2a-a562c7270a3b@googlegroups.com> Date: Sat, 1 Feb 2014 10:50:53 -0500 Subject: Re: Python prime numbers From: Larry Martell To: Panagiotis Anastasiou Content-Type: multipart/alternative; boundary=001a1135229661a66604f15a41df Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 95 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391269855 news.xs4all.nl 2963 [2001:888:2000:d::a6]:41796 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65224 --001a1135229661a66604f15a41df Content-Type: text/plain; charset=UTF-8 On Saturday, February 1, 2014, Panagiotis Anastasiou wrote: > 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 > If you put a comma at the end of the print statement it will suppress the newline. --001a1135229661a66604f15a41df Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Saturday, February 1, 2014, Panagiotis Anastasiou <panast24@gmail.com> wrote:
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 f= irst 200 prime numbers. The output must be formatted with a title and the p= rime numbers must be printed in 5 properly aligned columns . I have used th= is code so far :

numprimes =3D raw_input('Prime Numbers =C2=A0')
count =3D 0
potentialprime =3D 2

def primetest(potentialprime):
=C2=A0 =C2=A0 divisor =3D 2
=C2=A0 =C2=A0 while divisor <=3D potentialprime:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if potentialprime =3D=3D 2:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return True
=C2=A0 =C2=A0 =C2=A0 =C2=A0 elif potentialprime % divisor =3D=3D 0:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return False
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break
=C2=A0 =C2=A0 =C2=A0 =C2=A0 while potentialprime % divisor !=3D 0:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if potentialprime - divisor > = 1:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 divisor +=3D 1
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 else:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return True

while count < int(numprimes):
=C2=A0 =C2=A0 if primetest(potentialprime) =3D=3D True:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 print potentialprime
=C2=A0 =C2=A0 =C2=A0 =C2=A0 count +=3D 1
=C2=A0 =C2=A0 =C2=A0 =C2=A0 potentialprime +=3D 1
=C2=A0 =C2=A0 else:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 potentialprime +=3D 1

but i get the result in a single column . How can i get it in 5 rows? Can s= omeone help please


If you put a comma at the e= nd of the print statement it will suppress the newline.=C2=A0<= /div> --001a1135229661a66604f15a41df--