1

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 
Bruno Peres
  • 15,845
  • 5
  • 53
  • 89
  • Hi and welcome to StackOverflow. Please refer to https://stackoverflow.com/help/how-to-ask on how to ask a proper question and improve yours according the guidelines. – Fabian S. Sep 22 '17 at 08:21

3 Answers3

1

Never use built-in names as input

l = []


def input_x(s):
    for i in s:
        i = (ord(i)-90)%26+97
        l.append(chr(i))
    s = ''.join(l)
    return s
JJAACCEeEKK
  • 194
  • 1
  • 11
0
def input_x(s):
    result = ""
    for i in s:
        ci = (ord(i)-90)%26+ 97
        result += chr(ci)
    print(result)
Brooks Liu
  • 169
  • 8
0

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.