cipher encoding
Corey Richardson
kb1pkl at aim.com
Wed Jan 12 19:49:19 EST 2011
On 01/12/2011 07:39 PM, Corey Richardson wrote:
> On 01/12/2011 07:35 PM, Cathy James wrote:
>> 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:)
>>
>
> s = input("Enter message: ")
> key = int(input("Enter offset: ")) # I think that's what you wanted
> for letter in s:
> print(chr(ord(letter) + key), end = "")
>
Oh, and you wanted it reversed. That's not hard.
message = input("Enter message: ")
key = int(input("Enter offset: "))
new_message = ""
for char in message:
new_message += chr(ord(letter) + key)
print(new_message[::-1])
More information about the Python-list
mailing list