I am trying to manipulate user input strings using the ord() funtion. This effectively allows me to identify the decimal value of each character in the string. I have been able to return the value of the characters, but what I need to understand is how to store each value (to manipulate it), and how to return the characters associated with the new values.

In essence, the user inputs :

>>>cat

and the return is

99
97
116

I want to store these values, then manipulate them:

99+1=100
97+14=111
116-13=103

then returns:
'dog'

Fun with ascii values of a string ...

def ascii_list(s):
    """return a list of ascii values of the characters in string s"""
    return [ord(c) for c in s]

s = 'cat'
alist = ascii_list(s)
print alist  # [99, 97, 116]

# manipulate the list elements
alist[0] += 1
alist[1] += 14
alist[2] -= 13

# convert ascii to char
clist = [chr(e) for e in alist]
# join to form a word
print "".join(clist)  # dog

Extremely helpful, thanks for the post! And finally the use of char() sinks into my thick skull.

I'm greatful to all your contributions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.