📜  Python中的UwU文本转换器

📅  最后修改于: 2022-05-13 01:55:40.248000             🧑  作者: Mango

Python中的UwU文本转换器

UwU被用作表情符号来展示对可爱事物的反应。在这个表情符号中,“U”表示两只闭着的眼睛,“w”表示紧闭、兴奋的嘴唇。想象一下看到可爱的东西,比如婴儿可爱地打喷嚏,反应可能是 UwU,发音为“ooh-wooh”。

UwU 文本是原始文本已被“UwUfied”的术语类型。 UwU 文本应该是原始文本的更可爱的版本。它在某些在线社区中很受欢迎,主要是作为一种有趣的做法。

例子:

Input :  The quick brown fox jumps over the lazy dog.
Output : The quick bwown fox jumps ovew the wazy dog.

Input : Nooo! I was not late to work!
Output : Nyooo! I was nyot wate to wowk!

算法 :

  • 将所有 'R's 和 'r's 分别更改为 'w' 和 'W'。
  • 将所有“L”和“l”分别更改为“w”和“W”。
  • 如果当前字符是 'o' 或 'O' 而前一个字符是 'M'、'm'、'N' 或 'n',则在字符之间添加 'y'。
  • 如果任何字符的条件都不匹配,则保持该字符不变。
Python3
# Function to convert into UwU text
def generateUwU(input_text):
     
    # the length of the input text
    length = len(input_text)
     
    # variable declaration for the output text
    output_text = ''
     
    # check the cases for every individual character
    for i in range(length):
         
        # initialize the variables
        current_char = input_text[i]
        previous_char = ' 092; 048;'
         
        # assign the value of previous_char
        if i > 0:
            previous_char = input_text[i - 1]
         
        # change 'L' and 'R' to 'W'
        if current_char == 'L' or current_char == 'R':
            output_text += 'W'
         
        # change 'l' and 'r' to 'w'
        elif current_char == 'l' or current_char == 'r':
            output_text += 'w'
         
        # if the current character is 'o' or 'O'
        # also check the previous character
        elif current_char == 'O' or current_char == 'o':
            if previous_char == 'N' or previous_char == 'n' or previous_char == 'M' or previous_char == 'm':
                output_text += "yo"
            else:
                output_text += current_char
         
        # if no case match, write it as it is
        else:
            output_text += current_char
 
    return output_text
     
# Driver code
if __name__=='__main__':
    input_text1 = "The quick brown fox jumps over the lazy dog."
    input_text2 = "Nooo ! I was not late to work !"
    print(generateUwU(input_text1))
    print(generateUwU(input_text2))


输出 :

The quick bwown fox jumps ovew the wazy dog.
Nyooo! I was nyot wate to wowk!