Change each character in string to the next character in alphabet

前端 未结 8 1160
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-03 15:45

I am coding in Python 2.7 using PyCharm on Ubuntu.

I am trying to create a function that will take a string and change each character to the character that would be

8条回答
  •  余生分开走
    2021-01-03 16:31

    this is my code i think it is very simple

    def LetterChanges(st):
        index = 0
        new_word = ""
        alphapet = "abcdefghijklmnopqrstuvwxyzacd"
    
        for i in st.lower():
            if i.islower(): #check if i s letter
                index = alphapet.index(i) + 1 #get the index of the following letter
                new_word += alphapet[index]    
            else: #if not letter
                new_word += i    
        return new_word
    
    
    print LetterChanges(raw_input())
    

提交回复
热议问题