蟒蛇 :如何用s语言(字符串)解码文本



输入存在于s语言中的句子或文本中:Isis thasat yousour sisisteser?

输出存在没有s语言的相同句子:那是妹吗?

问题:我有以下代码,但有些东西不起作用。例如,我不能在 if 语句之后附加,而我的 if 语句太乱了。此外,打印(decoded_tekst)不起作用。

方法:我用两个变量("元音组"用于存储元音,"解码文本"用于存储辅音,如果"s"用于将其替换为元音组)遍历文本的不同位置。

text = input('Enter a text: ')
vowelgroup = []  
decoded_text = [] 
sentence = [] 
vowel = 'aeiou'
count = 0
for i in text:
    if i is not vowel and not "s":
        sentence = decoded_text.append(i)
    if i is vowel:
        vowelgroup = vowelgroup.append(vowel)
    if i is "s":
        decoded_text = sentence.append(vowelgroup)
    count += 1
    print(decoded_text)

你看起来对append如何工作有点困惑。 append只是将参数添加到列表的末尾,然后返回None 。例如:

l = [1,2]
a = l.append(3)
print a # None
print l # [1,2,3]

所以你只是像这样使用它:

l = [1,2]
l.append(3)
print l # [1,2,3]

最新更新