The internet is a very confounding place for some adults. Tom has just joined an online forum and is trying to fit in with all the teens and tweens. It seems like they're speaking in another language! Help Tom fit in by translating his well-formatted English into n00b language.
The following rules should be observed:
- "to" and "too" should be replaced by the number 2, even if they are only part of a word (E.g. today = 2day)
- Likewise, "for" and "fore" should be replaced by the number 4
- Any remaining double o's should be replaced with zeros (E.g. noob = n00b)
- "be", "are", "you", "please", "people", "really", "have", and "know" should be changed to "b", "r", "u", "plz", "ppl", "rly", "haz", and "no" respectively (even if they are only part of the word)
- When replacing words, always maintain case of the first letter unless another rule forces the word to all caps.
- The letter "s" should always be replaced by a "z", maintaining case
- "LOL" must be added to the beginning of any input string starting with a "w" or "W"
- "OMG" must be added to the beginning (after LOL, if applicable,) of a string 32 characters^(1) or longer
- All evenly numbered words^(2) must be in ALL CAPS (Example: ```Cake is very delicious.``` becomes ```Cake IZ very DELICIOUZ```)
- If the input string starts with "h" or "H", the entire output string should be in ALL CAPS
- Periods ( . ), commas ( , ), and apostrophes ( ' ) are to be removed
- ^(3)A question mark ( ? ) should have more question marks added to it, equal to the number of words^(2) in the sentence (Example: ```Are you a foo?``` has 4 words, so it would be converted to ```r U a F00????```)
- ^(3)Similarly, exclamation points ( ! ) should be replaced by a series of alternating exclamation points and the number 1, equal to the number of words^(2) in the sentence (Example: ```You are a foo!``` becomes ```u R a F00!1!1```)
^(1) Characters should be counted After: any word conversions, adding additional words, and removing punctuation. Excluding: All punctuation and any 1's added after exclamation marks ( ! ). Character count includes spaces.
^(2) For the sake of this kata, "words" are simply a space-delimited substring, regardless of its characters. Since the output may have a different number of words than the input, words should be counted based on the output string.
Example: ```whoa, you are my 123 <3``` becomes ```LOL WHOA u R my 123 <3``` = 7 words
^(3)The incoming string will be punctuated properly, so punctuation does not need to be validated.
def remove_punc(words):
    if "'" in words:
        temp_2 = words.partition("'")
        words = temp_2[0] + temp_2[-1]  
        
        words = remove_punc(words)
        
    if "." in words:
        temp_2 = words.partition(".")
        words = temp_2[0] + temp_2[-1]  
        
        words = remove_punc(words)
        
    if "," in words:
        temp_2 = words.partition(",")
        words = temp_2[0] + temp_2[-1]
        
        words = remove_punc(words)

    return words
    
def transw(words, old, new):
    temp_words = words.lower().replace(old, " "*len(old))
    result = ""
    threshold = 0
    for i in range(0, len(temp_words)):
        if temp_words[i] != " ":
            result = result + words[i]
        else:
            threshold += 1
            if threshold == len(old):           
                result = result + new
                threshold = 0
    return result
    


def n00bify(text):
    temp = text.split()
    result = ""
    for i in temp:
        
        i = transw(i, 'too', '2')
        i = transw(i, 'to', '2')
        i = transw(i, 'fore','4')
        i = transw(i, 'for', '4')
        i = transw(i, 'oo', '00')
        i = transw(i, 'be', 'b')
        i = transw(i, 'you', 'u')
        i = transw(i, 'are', 'r')
        i = transw(i, 'please', 'plz')
        i = transw(i, 'people', 'ppl')
        i = transw(i, 'really', 'rly')
        i = transw(i, 'have', 'haz')
        i = transw(i, 'know', 'no')
        i = transw(i, 's', 'z')
            
        i = remove_punc(i)
        
        if len(result) == 0:
            result = result + i
        else:
            result = result + " " + i
    
    if result[0] == "w" or result[0] == "W":
        result = "LOL" + " " + result
    if result[0] == "h" or result[0] == "H":
        result = result.upper()
    
            
    t_result = result.split()   
    
    count = 0
    for m in t_result:
        for n in m:
            if n == "!":
                break
            
            elif n.isalnum():
                count += 1
    
    count = count + len(t_result) - 1
    
    if count >= 32:
        if t_result[0] == "LOL":
            t_result = ["OMG"] + t_result
            t_result[0] = "LOL"
            t_result[1] = "OMG"
        else:
            t_result = ["OMG"] + t_result
    
    
    for k in range(0, len(t_result)):
        if "?" in t_result[k]:
            t_result[k] = t_result[k][:t_result[k].index("?")] + "?"*(len(t_result)-1) + t_result[k][t_result[k].index("?"):]
        
        if "!" in t_result[k]:
            add_in = ""
            for l in range(0, len(t_result)):
                if l % 2 == 0:
                    add_in = add_in + "!"
                else:
                    add_in = add_in + "1"
            
            t_result[k] = t_result[k][:t_result[k].index("!")] + add_in + t_result[k][t_result[k].index("!")+1:]        
                
    
    for i in range(0, len(t_result)):
        if i % 2 != 0:
            t_result[i] = t_result[i].upper()
    
                
    return " ".join(t_result)
def remove_punc(words):
    if "'" in words:
        temp_2 = words.partition("'")
        words = temp_2[0] + temp_2[-1]  
        
        words = remove_punc(words)
        
    if "." in words:
        temp_2 = words.partition(".")
        words = temp_2[0] + temp_2[-1]  
        
        words = remove_punc(words)
        
    if "," in words:
        temp_2 = words.partition(",")
        words = temp_2[0] + temp_2[-1]
        
        words = remove_punc(words)

    return words
    
def transw(words, old, new):
    temp_words = words.lower().replace(old, " "*len(old))
    result = ""
    threshold = 0
    for i in range(0, len(temp_words)):
        if temp_words[i] != " ":
            result = result + words[i]
        else:
            threshold += 1
            if threshold == len(old):           
                result = result + new
                threshold = 0
    return result
    


def n00bify(text):
    temp = text.split()
    result = ""
    for i in temp:
        
        i = transw(i, 'too', '2')
        i = transw(i, 'to', '2')
        i = transw(i, 'fore','4')
        i = transw(i, 'for', '4')
        i = transw(i, 'oo', '00')
        i = transw(i, 'be', 'b')
        i = transw(i, 'you', 'u')
        i = transw(i, 'are', 'r')
        i = transw(i, 'please', 'plz')
        i = transw(i, 'people', 'ppl')
        i = transw(i, 'really', 'rly')
        i = transw(i, 'have', 'haz')
        i = transw(i, 'know', 'no')
        i = transw(i, 's', 'z')
            
        i = remove_punc(i)
        
        if len(result) == 0:
            result = result + i
        else:
            result = result + " " + i
    
    if result[0] == "w" or result[0] == "W":
        result = "LOL" + " " + result
    if result[0] == "h" or result[0] == "H":
        result = result.upper()
    
            
    t_result = result.split()   
    
    count = 0
    for m in t_result:
        for n in m:
            if n == "!":
                break
            
            elif n.isalnum():
                count += 1
    
    count = count + len(t_result) - 1
    
    if count >= 32:
        if t_result[0] == "LOL":
            t_result = ["OMG"] + t_result
            t_result[0] = "LOL"
            t_result[1] = "OMG"
        else:
            t_result = ["OMG"] + t_result
    
    
    for k in range(0, len(t_result)):
        if "?" in t_result[k]:
            t_result[k] = t_result[k][:t_result[k].index("?")] + "?"*(len(t_result)-1) + t_result[k][t_result[k].index("?"):]
        
        if "!" in t_result[k]:
            add_in = ""
            for l in range(0, len(t_result)):
                if l % 2 == 0:
                    add_in = add_in + "!"
                else:
                    add_in = add_in + "1"
            
            t_result[k] = t_result[k][:t_result[k].index("!")] + add_in + t_result[k][t_result[k].index("!")+1:]        
                
    
    for i in range(0, len(t_result)):
        if i % 2 != 0:
            t_result[i] = t_result[i].upper()
    
                
    return " ".join(t_result)