Solution Exercise 17

Write a function translate() that will translate a text into "robber's language" . That is, double every consonant and place an occurrence of "o" in between. For example, translate("this is fun") should return the string "tothohisos isos fofunon".

def translate(text):
    #Instead of having a string with all consonants
    #we use vowels as they are fewer
    vowels = "aeiouy"
    robberStr = ""
    for c in text:
        #As we want to find consonants we check if the
        #character is not in vowels but we also need
        #to make sure that the character is alphabetic
        #and that is the reason we have c.isalpha() here
        if c not in vowels and c.isalpha():
            robberStr += c + "o" + c
        else:
            robberStr += c
    return robberStr

def main():
    print(translate("this is fun"))
    
if __name__ == '__main__':
    main()