My code is this:
def cod(n):
for i in n:
i = str(i)
if len(n) == 1:
ascii = ord(i)
return ascii
else:
ascii = ord(i) + cod(ord(i))
return ascii
The error that returns is as follows:
Traceback (most recent call last):
File "python", line 1, in <module>
File "python", line 8, in codifica
File "python", line 2, in codifica
TypeError: 'int' object is not iterable
I'm basically using ord()
to get the ASCII character number. When I call only one character, everything works fine. If you try to spend more than one you start the problems.
The problem seems to be that the variable i
is being treated as integer but supposedly I convert to string when doing i = str(i)
What I want is that when executing the function cod('ola')
it returns 11110897
which corresponds to the conversion of each of the characters to ASCII.
Can anyone help me figure out where I'm failing?