anti_vowel - Who may help with changing the code?


#1

Hello everybody, I'm learning how to use this Community Forum, so sorry if I made mistake in starting new topic. I want to ask how can I change my code in order to change my anti_v and return correct result? If I write print instead of return at the end of function - it prints correct answer, but tells about error because of returning "None" instead of "Hll My Frnd!" Here's my code:

 def anti_vowel(text):
 for anti_v in text:
        if anti_v in "aeiou" or anti_v in 'AEIOU':
             continue  
         elif anti_v not in "aeiou"  or anti_v not in 'AEIOU':
             print anti_v,
     return anti_v
print anti_vowel("Hello My Friend!")

#2

@nurtas_14,
Python uses indentation
in order to determine which code should stand/execute together as a code-block

def anti_vowel(text):
    # 4-space indentation
    # create a variable to capture vowel-characters
    capt_vowel = []
    for anti_v in text:
        # 4-space indentation
        # all code in this FOR-IN indentation-level
        if anti_v in "aeiou" or anti_v in 'AEIOU':
            # IF code-block
            continue
        else:
            # ELIF is not needed
            # elif anti_v not in "aeiou"  or anti_v not in 'AEIOU':
            capt_vowel.extend(anti_v)
    # end of FOR-IN loop
    # a return will exit the function
    return "".join(capt_vowel)

print anti_vowel("Hello My Friend!")

Reference:

== the Book ==
[your question] site:python.org

== discussions / opinions ==
python [your question] site:stackoverflow.com


#3

Thank you for your very useful clarification!