palindrome

Seymore4Head Seymore4Head at Hotmail.invalid
Mon Nov 16 23:48:48 EST 2015


On Tue, 17 Nov 2015 10:09:27 +0530, Abhiram R
<abhi.darkness at gmail.com> wrote:

>On Tue, Nov 17, 2015 at 9:59 AM, Seymore4Head <Seymore4Head at 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.



More information about the Python-list mailing list