'How do I find multiple phrases within a block of text for use in a word scrambler and translator script?

I'm 1 week into learning my first language, Python! So go easy on me, please :)

So my case sensitive word scrambler program is essentially an a = b scrambler, but instead of single units it replaces it with an entire phrase. I'm using this to turn normal sentences into crazy rants about needing to change my name. Which is something I've been doing all my life.

The scrambler looks like this:

def scramble(phrase):
    scrambled = ""
    for letter in phrase:
        if letter in "A":
            scrambled = scrambled + "I need to change my name! "
    for letter in phrase:
        if letter in "a":
            scrambled = scrambled + "Gonna change my name to Sclurbs! "
    return scrambled
print(scramble(input("enter a phrase")))

it repeats for every upper and lower case letter with different phrases related to the rant

The translator looks like this:

def translate(phrase):
    translation = ""
    if "I need to change my name!" in phrase:
            translation = translation + "A"
    if "Gonna change my name to Sclurbs!" in phrase:
            translation = translation + "a"
    return translation
print(translate(input("enter a phrase")))

This doesn't work because it stops as soon as it finds the first time the phrase is presented as input, and doesn't continue to see if the phrase is used again.

I know I need a for loop in here somewhere to keep the chain going, but I don't know how to express it in a way that doesn't index each letter in the string individually and not the whole phrase itself. How does?

Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source