[Tutor] Decoding

Khamid Nurdiev khamid.nurdiev at gmail.com
Sun Aug 12 22:15:37 CEST 2007


Hello All,
 I am currently learning python with the book "Python programming: An
introduction to CS" by John M. Zelle and have come the section where he
speaks of encoding messages. Currently the basic snippet looks like this:

def dec():
> >     import string
> >     message=raw_input("Enter the message to decode: ")
> >     result=''
> >     for x in string.split(message):
> >         result=result+chr(eval(x))
> >     return result
> >
> > print dec()
>
>
it works fine as expected but I want to enter the message as a variable
like:
a='12 34 84 39 122'
and when the function dec() invoked, i would just enter "a" as an input and
thus have changed the code a little bit but it is not working.

def dec():
> >     import string
> >     message=raw_input("Enter the message to decode: ")
> >     a=message[1:-1]
> >     result=''
> >     for x in string.split(a):
> >         result=result+chr(eval(x))
> >     return result
> >
> > print dec()
> >
>
Have tried many ways, i don't want to write them all here as they will take
too much space. None of them work. maybe you guys know some way out? or
where is it going wrong?

 Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070813/dd9d9a08/attachment.html 


More information about the Tutor mailing list