8/15 - anti_vowel: Why 1 of my 2 solutions doesn't work?


#1




I used 2 ways to solve the problem and ran them in Python GUI. Both of them can get the right result("Hy lk Wrds!").

However, on the online board, only the 2nd solution(codes after line 13) works. The 1st solution(codes before line 13) will get this error: Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "None" when it should return "Hy lk Wrds!".



Replace this line with your code.


#2

Can you please give the link tot he exercise please ?


#3

I think it's because you didn't return new in your first example, you printed it. A function will always look for a return command.


#5

This is a solution I could gather from your code .

def anti_vowel(text):
vowels = ['a','A','e','E','i','I','o','O','u','U']
NoVowels = ""
for char in text:
    for vowel in vowels:
        if char == vowel:
            break
    else:
        NoVowels += char

return NoVowels

#6

Or

def anti_vowel(text):

    word = []
    vowel_word = ""


    for i in text:
        word.append(i)

    for i in range(len(word)):
        for i in word:
            x = word.index(i)
            if i in "aeiouAEIOU":
                word.pop(x)       

    for i in word:
        vowel_word += "".join(i)


    return vowel_word   

print anti_vowel("Oii, Words")

#7

There is a link at the very beginning, not for you?


#8

I don't need a link anymore I figured it out look up ^


#9

Thank you very much. However, I'm not to find another solution here. My question is what's wrong with my 1st solution, and why it can run correctly in Python GUI but not here.


#10

did you not read my post? you used print and not return


#11

OH...I missed your reply. SORRY. Thank you very much. But why the 1st works in Python GUI and coderpad.io?


#12

Well in an IDE, they're not looking for anything specifically, so it's fine if you print it, but the lesson's correctness test is actually looking for you to return the string, so it does matter, but in GUI, it wouldn't really.
Hope I could help. :))


#13

OOOHHH! I see. Thank you Kyleaw!


#14

Oh Sorry XD Didn't see it XD


#15

Thanks all the same!:clap:


#16

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