Programming Questions

  • Newest
  • Popular Tags
  • Ask Question
  • Letter Changes (Python)
    def LetterChanges(sen):
        newWord = '';
        newChar = 0;
        for i in range(len(sen)):
            if sen[i] == chr(32):
                newWord += sen[i];
            elif sen[i].isalnum() and not sen[i].isdigit():
                newChar = ord(sen[i]);
                newChar += 1;
                newWord += chr(newChar);
                newWord += sen[i];
        return newWord;
    I run some test cases, and they seem to turn out the one that I want them too. I understand that one of the problems with this solution is that if there is a 'z' or 'Z' then adding one to it will produce an incorrect result; however, when I submit my code it says that "hello world" is producing an incorrect return value. Am I not seeing something? Any help is appreciated. Thanks!
    tryhard posted this question on 11/9/15 | letter, python
  • +
  • 0
  • -
  • def LetterChanges(input):
      table = str.maketrans("abcdefghijklmnopqrstuvwxyz", "bcdEfghIjklmnOpqrstUvwxyzA")
      return input.translate(table)
  • +
  • 0
  • -
  • Can anybody tell me why this code does not work? I'm a beginner so I believe I must be doing something essentially wrong here.
    def LetterChanges(str):
        # code goes here
        str = string(str)
        import string
        ab_st = string.lowercase
        new_word = ""
        for l in range(len(str)):
            if l == "z":
                new_word.join(ab_st([l] + 1))
        return new_word
    # keep this function call here  
    print LetterChanges(raw_input()) 
    When I run the code by inputing "hello", the error that I get is: Traceback (most recent call last): File "python", line 15, in <module>NameError: name 'hello' is not defined Many thanks for your help.
  • +
  • 0
  • -
  • Is that all your code? "[...] Then capitalize every vowel in this new string (a, e, i, o, u) and finally return this modified string."
  • +
  • 0
  • -
  • What is your code intending to do aside from incrementing to the next character in sequence? The result I receive from "Hello World" is "Ifmmp Xpsme".
    Log in to write an answer.