cipher encoding

Krzysztof Bieniasz krzysztof.t.bieniasz at gmail.com
Thu Jan 13 05:54:01 EST 2011


> Dear all,
>  
> I hope someone out there can help me.
>  
>  The output string of my code is close to what i need, but i need it
> 1)printed on one line and
> 2) reversed
>  
> #mycode:
> s= input("Enter message: ")
> key=1
> for letter in s:
>     num=(chr(ord(letter)+1))
>     print(num)
> #or is there a better way to rewrite it with elementary level Python,
> which happens 2b my current ranking.
> #Your insight is always appreciated:)

If you want it on one line the simplest thing would be to have it in one 
string:

num=''
for letter in s:
    num+=chr(ord(letter)+1)
print num[::-1]

But if you don't want it that way you can simply write

print num,

in your original code. The comma suppresses '\n' at the end of print. 
Only you have to feed letters to the loop in reverse order if you want it 
reversed.



More information about the Python-list mailing list