Python中的土耳其语单词加密

2024-07-03 06:26:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我对python有一个想法-我该怎么做?你知道吗

应该是这样的

Text Input

Rüzgar

Process

  •    R --> consonant
       ü --> vowel
       z --> consonant
       g --> consonant
       a --> vowel
       r --> consonant
    
    • 列出单词 [r,ü,z,g,a,r]

-如果第一个字母是辅音,什么也不要做,如果第二个字母是元音,则转到第二个字母,添加“g”并再次添加相同的元音

zgagar

然后打印出来

第一步

text = "abcd"

word_list = []

for i in range(0, len(text)):
    word_list.append(text[i])
    i+=1

for i in range(0, len(word_list)):
 if(word_list[i]=='A' or word_list[i]=='a' or word_list[i]=='E' or word_list[i] =='e' or word_list[i]=='I'
 or word_list[i]=='i' or word_list[i]=='O' or word_list[i]=='o' or word_list[i]=='U' or word_list[i]=='u'):
    print(word_list[i], "is a Vowel")
    i+=1

else:
    print(word_list[i], "is a Consonant")
    i+=1

Code output

我没有任何想法来保持代码和解决第一个问题


Tags: ortextinforlenis字母range
3条回答

这里有一句话供你学习:

vowels = "aeiou"  # You may add vowels specific to Turkish alphabet here 
text = "hello world"

print("".join([letter + ("g" + letter if letter in vowels else "") for letter in text]))

将打印

hegellogo wogorld

你需要反复阅读你的文章。为了方便起见,请将文本设置为小写。你知道吗

text = "rüzgar"
vowels = ['a', 'e', 'ı', 'i', 'u', 'ü', 'o', 'ö']

index = 0
for each_character in text.lower():
    if each_character in vowels:
        text = text[:index+1] + 'g' + each_character + text[index+1:]
    index = index + 1

print(text)

输出将是:rügüzgagar

def func(word):
    vowel = ['a','e','i','o','u']
    word_list = list(word)
    for index, char in enumerate(word_list):
        if char in vowel:
            word_list[index] = '{}g{}'.format(char,char)
    return ''.join(word_list)


print(func('hello world!'))          

输出

hegellogo wogorld!

相关问题 更多 >