Identation

Define a function called anti_vowel that takes one string, text , as input and returns the text with all of the vowels removed.

my code was

def anti_vowel(text):
  	newtext=''
  	vowels = 'aeiouAEIOU'
  	for n in text:
      	if n not in vowels:
   				newtext = newtext + n
  	return text  
  
print anti_vowel ('bab')

I DID THE EXACT SAME THING AS THE SOLUTION however, the response given was
File “python”, line 15
if n not in vowels:
^
IndentationError: expected an indented block

may i know why

Your code is:

        for n in text:
      	if n not in vowels:
   				newtext = newtext + n

You need to indent after the for n in text:, as that’s how Python knows what’s inside your for loop.

If there’s no indented block after the for, Python interprets that as a loop block with no content which is an error.

:slight_smile:

1 Like