Anti_vowel code pretty much works with print but with return doesn't


#1

My code feels so close to the desired result but maybe that’s the point is to try it with return like the instructions ask… but my code prints:

H y l k W r d s !

Is there a way to keep the basic structure of my code but use the return function. When I change print for return it returns:

(‘H’,)



def anti_vowel(text):
    for char in text:
        if char in "aeiouAEIOU":
            del char
        else:
            print char,
            
anti_vowel("Hey look Words!")



#3

In order to print the result of a function that uses return. Simply print the result of calling the function…

print anti_vowel("Hey look Words!")

However, the way your code is currently structured, it will always only return one letter. This is because a function ends the moment a return key is reached. Therefore, perhaps you should try following this template:

def FUNCTION(PARAMETER):
    for INDIVIDUAL_ITEM in PARAMETER:
        if INDIVDUAL_ITEM in "aeiouAEIOU":
            PARAMETER = PARAMETER.replace(INDIVIDUAL_ITEM, "")
    return PARAMETER

Make sure not to just follow the template and move on. I want to make sure that you understand how and why this works. If you have any questions, just ask.


#4

def anti_vowel(text):
    for char in text:
        if char in "aeiouAEIOU":
            text = text.replace(char, "")
    return text

Yea that’s pretty clean and straightforward. I took out the “str” in
for INDIVIDUAL_ITEM in str(PARAMETER)
It is a string so I don’t need to declare str before it right?

Thanks so much though. I was close! Just had to replace last 3 lines with:

text = text.replace(char, “”)
return text

I find myself googling “difference between return and print” still. So thanks for answering that a bit. Basically return will end my function

Thanks, I am glad I was somewhat close with my logic. Sometimes I don’t know where to start with these problems


#5

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