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


Groups > comp.lang.python > #98910

Re: palindrome

From Abhiram R <abhi.darkness@gmail.com>
Newsgroups comp.lang.python
Subject Re: palindrome
Date 2015-11-17 10:25 +0530
Message-ID <mailman.377.1447736189.16136.python-list@python.org> (permalink)
References <s4bl4bd739gfq92c5hipb16grv8a5fh5pb@4ax.com> <mailman.376.1447735216.16136.python-list@python.org> <78cl4bljie79vqr80d1g084jm8ma3k0r9k@4ax.com>

Show all headers | View raw


On Tue, Nov 17, 2015 at 10:18 AM, Seymore4Head <Seymore4Head@hotmail.invalid
> wrote:

> On Tue, 17 Nov 2015 10:09:27 +0530, Abhiram R
> <abhi.darkness@gmail.com> wrote:
>
> >On Tue, Nov 17, 2015 at 9:59 AM, Seymore4Head
> <Seymore4Head@hotmail.invalid>
> >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=""
> >> letcount=4
> >> count=0
> >> abc='abcdefghijklmnopqrstuvwxyz'
> >> while True:
> >>     for i in range(letcount):
> >>         a=random.choice(abc)
> >>         str1+=a
> >>     print str1
> >>     count+=1
> >>     if str1==str1[::-1]:
> >>         break
> >>     else:
> >>         str1=""
> >> print "Tries= ",count
> >> print str1
> >> --
> >>
> >> ?
> >
> >The question asks to get an input from the user and print if it's a
> >palindrome or not.
> >It should be just
> >
> >strA=raw_input()
> >if strA==strA[::-1]:
> >    print "Palindrome"
> >else:
> >    print "Not"
> >
> >Right? Am I missing something? Why are you generating random strings and
> >trying to check for palindromes??
> >
> The instructions do ask for input.  I am lazy.  I thought it would be
> cool to have random input instead of just typing a phrase.
> --
>
>
​Haha. Nice. Although with your length of string and the range you're
picking from,the chances of you getting a palindrome are (1/24!)  :D ​




-- 
-Abhiram R

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


Thread

palindrome Seymore4Head <Seymore4Head@Hotmail.invalid> - 2015-11-16 23:29 -0500
  Re: palindrome Abhiram R <abhi.darkness@gmail.com> - 2015-11-17 10:09 +0530
    Re: palindrome Seymore4Head <Seymore4Head@Hotmail.invalid> - 2015-11-16 23:48 -0500
      Re: palindrome Abhiram R <abhi.darkness@gmail.com> - 2015-11-17 10:25 +0530
      Re: palindrome Peter Otten <__peter__@web.de> - 2015-11-17 10:48 +0100
  Re: palindrome Peter Otten <__peter__@web.de> - 2015-11-17 10:31 +0100

csiph-web