3

I thought everything was properly indented here but I am getting an IndentationError: expected an indented block at the else: statement. Am I making an obvious mistake here?

def anti_vowel(text):
    new_string = ""
    vowels = "aeiou"
    for letter in text:
       for vowel in vowels:
           if (lower(letter) == vowel):
               #do nothing
           else:
               #append letter to the new string
               new_string += letter
    return new_string
ricoflow
  • 115
  • 1
  • 8
  • 3
    For empty blocks you should use `pass`. – Ashwini Chaudhary Feb 13 '14 at 20:37
  • 2
    In case you already knew that you had to put something in the `if` block and thought that you had… a comment isn't a statement. It's simplest to think of it as if comments get removed before the code gets parsed. – abarnert Feb 13 '14 at 20:38

4 Answers4

7

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.

BrenBarn
  • 242,874
  • 37
  • 412
  • 384
7

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
davidism
  • 121,510
  • 29
  • 395
  • 339
Cilyan
  • 7,883
  • 1
  • 29
  • 37
0

You can't do this.

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

Try:

if (lower(letter) == vowel):
    #do nothing
    pass
Tyler
  • 17,669
  • 10
  • 51
  • 89
-1

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

Toby
  • 350
  • 1
  • 4
  • 10