Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Abhiram R Newsgroups: comp.lang.python Subject: Re: palindrome Date: Tue, 17 Nov 2015 10:09:27 +0530 Lines: 45 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de aini+HFj3CZ02SDX7ykezgfvGdwONX/TNv21T+BsJrdA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'else:': 0.03; 'cc:addr :python-list': 0.09; '"not"': 0.16; 'better?': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'true:': 0.16; 'wrote:': 0.16; 'input': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'trying': 0.22; 'am,': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'not.': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'asks': 0.29; 'random': 0.29; 'print': 0.30; 'right?': 0.33; 'tue,': 0.34; 'skip:& 20': 0.35; 'received:google.com': 0.35; 'nov': 0.35; 'should': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'thanks': 0.37; 'missing': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'why': 0.39; 'url:2014': 0.66; 'here': 0.66; 'seymore4head': 0.84; 'url:03': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=sJShctso3QVCuuT1vyfmcEMUt3d43ZAehMfSFbh+wzk=; b=XdeEanSwNhRmnMTv99F4n0AZwg2hy2XsztGq5p2df1u7riROk8gUkvHISA5ONbdmcB yFnMiM5L7KHNLxXZ6//m2WtEZSAtpbMUAQ5F2s1V6EHMi+CWXVwDsCYaRSYvMJxBw1ob uuPgNgL8KpPGhsgVWosFK5tQoGRZ4l/1eUMUykXPMYXFa2WuaMBL31JMN7iHuhGf0QdG DBjlD9otFaFIxM2kQ3JcJzySrfOM1uUGJ1XNmC5wHQFRcznduoSG2RodblrtOr3mwThM Fn5w+VBM4gaTx+BvQ+MttBabNh9S6q4n6w9xz6ggbqQkVsPxWhOh9gnc6GXXHy/zfnm3 /VQg== X-Received: by 10.50.59.179 with SMTP id a19mr11274igr.59.1447735207388; Mon, 16 Nov 2015 20:40:07 -0800 (PST) In-Reply-To: X-Content-Filtered-By: Mailman/MimeDel 2.1.20+ X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:98908 On Tue, Nov 17, 2015 at 9:59 AM, Seymore4Head wrote: > http://www.practicepython.org/exercise/2014/03/12/06-string-lists.html > > Here is my answers. What would make it better? > > import random > str1=3D"" > letcount=3D4 > count=3D0 > abc=3D'abcdefghijklmnopqrstuvwxyz' > while True: > for i in range(letcount): > a=3Drandom.choice(abc) > str1+=3Da > print str1 > count+=3D1 > if str1=3D=3Dstr1[::-1]: > break > else: > str1=3D"" > print "Tries=3D ",count > print str1 > -- > > =E2=80=8B The question asks to get an input from the user and print if it's a palindrome or not. It should be just strA=3Draw_input() if strA=3D=3DstrA[::-1]: print "Palindrome" else: print "Not" Right? Am I missing something? Why are you generating random strings and trying to check for palindromes?=E2=80=8B Thanks Abhiram R (IRC - abhiii5459_ ; Twitter - https://twitter.com/abhiii5459)