FAQ
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:)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110112/4a252ce9/attachment.html>

Search Discussions

  • Corey Richardson at Jan 13, 2011 at 12:39 am

    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 = "")
  • Corey Richardson at Jan 13, 2011 at 12:49 am

    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])
  • MRAB at Jan 13, 2011 at 1:05 am

    On 13/01/2011 00:49, Corey Richardson wrote:
    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])
    It's neater with:

    for char in reversed(message):

    then you don't need 'new_message'.
  • Nick Stinemates at Jan 13, 2011 at 12:50 am
    Try

    print s[::-1]

    Nick
    On Wednesday, January 12, 2011, 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:)
  • Krzysztof Bieniasz at Jan 13, 2011 at 10:54 am

    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJan 13, '11 at 12:35a
activeJan 13, '11 at 10:54a
posts6
users5
websitepython.org

People

Translate

site design / logo © 2022 Grokbase