-1

I'm having a bit of trouble, I took an input from the user in the main function and then is supposed to go through the uppercase function, the result of that function is supposed to go to the abbreviation function and the result of that is supposed to go to the replace function and then print the final result .

letter_replacements = {
        'E': '3',
        'O': '0',
        'C': '[',
        'A': '@',
        'K': '|<',
        'I': '1',
        'S': '$',
        'N': '/\/'

    }
abberviation_replacements = {
        'TOMORROW': 'TMR',
        'ABOUT': 'BOUT',
        'PLEASE': 'PLZ',
        'BEFORE': 'B4'
    }
    def uppercase(newWord): 
        new_uppercase=''
        for letters in newWord:
            if ord(letters) > 96:
                new_uppercase += chr(ord(letters)-32)
            else:
                new_uppercase += letters
        print(new_uppercase)
        return new_uppercase

def replace_abberviation():
        new_abber=new_uppercase.split()
        for i in range(len(li)):
            if new_abber[i] in abberviation_replacements:
                new_abber[i]=abberviation_replacements[new_abber[i]]
        print(" ".join(new_abber))

 def replace_letter(newString):
        old,new = [],[]
        char = input("Change: ")
        for ch in char:
            if letter_replacements.get(ch):
                newString = newString.replace(ch, letter_replacements.get(ch))
            print(newString)

#this is the definition of your main function
    def main():
        print("Hello, And Welcome to this Slang Program")
        cap_letters = input("Please enter your string here: ")  
        uppercase(cap_letters)
        replace_abberviation()
        # write the part of the program that interacts with the user here
        replace_letter(uppercase(cap_letters))

# these should be the last two lines of your submission
if __name__ == '__main__':
    main()
Blame
  • 29
  • 3
  • 1
    `uppercase` returns a new string, it doesn't alter the string you passed in. You need to use the return `cap_letters = uppercase(cap_letters)`. And then the `replace_` functions aren't returning their result, they're printing it. I originally voted to close this as "typo/not helpful to future users", but this is also a partial dupe of [this](https://stackoverflow.com/questions/750136/how-is-returning-the-output-of-a-function-different-from-printing-it). – Carcigenicate Nov 16 '19 at 00:12
  • Welcome to StackOverflow. [On topic](https://stackoverflow.com/help/on-topic), [how to ask](https://stackoverflow.com/help/how-to-ask), and ... [the perfect question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) apply here. IN particular, please ask a single, focused question; this code rambles through multiple problems, such that your question reduces to "it doesn't work". – Prune Nov 16 '19 at 00:33
  • Back up and take the functions one at a time. Make sure each one works independently, returning its result as expected. *Then* you'll have a solid basis on which to try linking them together ... at which point, you'll search on line for a tutorial or prior SO questions that deal with passing the result of one function to the next. When you get through *that* implementation effort, you will have a good question to ask here. – Prune Nov 16 '19 at 00:35

1 Answers1

0

I changed your code as it wasn't working as expected, maybe this will help get you started on your project:

letter_replacements = {
        'E': '3',
        'O': '0',
        'C': '[',
        'A': '@',
        'K': '|<',
        'I': '1',
        'S': '$',
        'N': '/\/'

    }
abberviation_replacements = {
        'TOMORROW': 'TMR',
        'ABOUT': 'BOUT',
        'PLEASE': 'PLZ',
        'BEFORE': 'B4'
    }
def uppercase(newWord): 
        new_uppercase=''
        for letters in newWord:
            if ord(letters) > 96:
                new_uppercase += chr(ord(letters)-32)
            else:
                new_uppercase += letters
        print(new_uppercase)
        return new_uppercase

def replace_abberviation(new_uppercase):
        new_abber=new_uppercase.split()
        for i in range(len(new_abber)):
            if new_abber[i] in abberviation_replacements:
                new_abber[i]=abberviation_replacements[new_abber[i]]
        print(" ".join(new_abber))

def replace_letter(newString):
        old,new = [],[]
        char = input("Change: ")
        for ch in char:
            if letter_replacements.get(ch):
                newString = newString.replace(ch, letter_replacements.get(ch))
            print(newString)

#this is the definition of your main function
def main():
        print("Hello, And Welcome to this Slang Program")
        cap_letters = input("Please enter your string here: ")  
        replace_abberviation(uppercase(cap_letters))
        # write the part of the program that interacts with the user here
        replace_letter(uppercase(cap_letters))

# these should be the last two lines of your submission
if __name__ == '__main__':
    main()
oppressionslayer
  • 6,942
  • 2
  • 7
  • 24
  • 1
    btw, since your new to stackoverflow, would you be so kind to give the other questioners on your other posts a check on the question mark for the best answer? Thx, this would be greatly appreciated by those with the best answers for your questions! – oppressionslayer Nov 16 '19 at 01:08