Convert number values into ascii characters?
<p>The part where I need to go from the number values I obtained to characters to spell out a word it not working, it says I need to use an integer for the last part?</p>

<p>accept string</p>

<pre><code>print "This program reduces and decodes a coded message and determines if it is a palindrome"
string=(str(raw_input("The code is:")))
</code></pre>

<p>change it to lower case </p>

<pre><code>string_lowercase=string.lower()
print "lower case string is:", string_lowercase
</code></pre>

<p>strip special characters</p>

<pre><code>specialcharacters="1234567890~`!@#$%^&amp;*()_-+={[}]|\:;'&lt;,&gt;.?/"

for char in specialcharacters:
    string_lowercase=string_lowercase.replace(char,"")

print "With the specials stripped out the string is:", string_lowercase
</code></pre>

<p>input offset</p>

<pre><code>offset=(int(raw_input("enter offset:")))
</code></pre>

<p>conversion of text to ASCII code</p>

<pre><code>result=[]
for i in string_lowercase:
    code=ord(i)
    result.append([code-offset])
</code></pre>

<p>conversion from ASCII code to text</p>

<pre><code>text=''.join(chr(i) for i in result)
print "The decoded string is:", text.format(chr(result))
</code></pre>

<p>While doing <code>.append()</code> to list, use <code>code-offset</code> instead of <code>[code-offset]</code>. As in later you are storing the value as a list (of one ASCII) instead of storing the ASCII value directly.</p>

<p>Hence your code should be:</p>

<pre><code>result = []
for i in string_lowercase:
    code = ord(i)
    result.append(code-offset)
</code></pre>

<p>However you may simplified this code as:</p>

<pre><code>result = [ord(ch)-offset for ch in string_lowercase]
</code></pre>

<p>You may even further simplify your code. The one line to get decoded string will be:</p>

<pre><code>decoded_string = ''.join(chr(ord(ch)-offset) for ch in string_lowercase)
</code></pre>

<p><strong>Example</strong> with offset as 2:</p>

<pre><code>&gt;&gt;&gt; string_lowercase = 'abcdefghijklmnopqrstuvwxyz'
&gt;&gt;&gt; offset = 2
&gt;&gt;&gt; decoded_string = ''.join(chr(ord(ch)-offset) for ch in string_lowercase)
&gt;&gt;&gt; decoded_string
'_`abcdefghijklmnopqrstuvwx'
</code></pre>

python ascii chr