Anti_vowels


#1



Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "H" when it should return "Hy lk Wrds!".


this code works perfectly outside the function, but failed to work inside the function.
please explain this error


def anti_vowel(text):
    for d in text:
        if d not in "aeiouAEIOU":
            return d
print anti_vowel("you are good")


#2

what do you mean? Using return keywords outside a function cause error message

A function ends the moment a return keyword is reached, if a return keyword is reached in a loop, the loop will break (in order for the function to end)

in other words, your loop breaks in its first iteration

You need to return the reversed string at the end of your function


#3

sry don't understand
"You need to return the reversed string at the end of your function"
what is reversed string?

Outside function means, without using function
like this:- for d in "you are good":
if d not in "aeiouAEIOU":
print d,
it works perfectly.


#4

Good, because i made a mistake. I somehow got anti_vowels and reversed mixed up

But now you need to actually make a string (or list, which join into a string at the end of your function) to store the string without vowels, and return this string

the , at the end of your print statement will print all characters on the same line, nice and cleverly found, but that won't cut it in this exercise


#5

thnx for reply
I got u what u want to say.
I know that by using list it can work.
But how to use "return" inside the loop without breaking the loop.
Because there is also other functions we have to do this


#6

you can't. Return will cause the function to end

So you need to loop over text, append constants to list, then after the loop, join the list into a string, and return the string which only contains constants (no vowels)


#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.