Search code examples
pythonasciichrord

How to return an array of characters in cypher program (python3)


i wrote code when input for example is "a" he return "h". But how i can make it work if i want to return array of characters, for example if is input "aa" to return "hh"?

def input(s):
    for i in range(len(s)):
        ci = (ord(s[i])-90)%26+97
        s = "".join(chr(ci))
    return s 

Solution

  • You can use strings to do this. My variable finaloutput is a string that I will use to store all the updated characters.

    def foo(s):
        finaloutput = ''
        for i in s:
            finaloutput += chr((ord(i)-90)%26+97)
        return finaloutput
    

    This code uses string concatenation to add together a series of characters. Since strings are iterables, you can use the for loop shown above instead of the complex one that you used.