Python: Expected an indented block

我们两清 提交于 2019-11-28 14:34:14
Cilyan

Do nothing translates to using the pass keyword to fill an otherwise empty block (which is not allowed). See the official documentation for more information.

def anti_vowel(text):
    new_string = ""
    vowels = "aeiou"
    for letter in text:
       for vowel in vowels:
           if (lower(letter) == vowel):
               #do nothing
               pass
           else:
               #append letter to the new string
               new_string += letter
    return new_string

You need to put something inside the if block. If you don't want to do anything, put pass.

Alternatively, just reverse your condition so you only have one block:

if lower(letter) != vowel:
    new_string += letter

Incidentally, I don't think your code will do what you intend it to do, but that's an issue for another question.

You can't do this.

if (lower(letter) == vowel):
    #do nothing

Try:

if (lower(letter) == vowel):
    #do nothing
    pass

This can be caused by mixing tabs and spaces. However, this is probably caused by having nothing inside your if statement. You can use "pass" as a placeholder (see example below).

    if condition:
        pass

Information on pass: http://docs.python.org/release/2.5.2/ref/pass.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!