ASCII characters do not work in exercise 8/15


#1

Hi!

I am doing the anti_vowel exercise and even though my code (others I tried from this forum work) works for many sentences, I still get this error message:

'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128)

The symbol in position 0 is "¡".

My code is:

def anti_vowel(text):
text = str(text)
vowels = "aeiouAEIOU"
new_word = ""
for i in text:
count = 0
for j in vowels:
if j == i:
pass
else:
count += 1
if count == 10:
new_word = new_word + i
else:
pass
print new_word

I understand there is a better and simpler code that is working, but why is this error happening? How could I fix it?


#2

Perhaps you wanna return new_word instead of print it

def anti_vowel(text):
    text = str(text)
    vowels = "aeiouAEIOU"
    new_word = ""
    for i in text:
        count = 0
        for j in vowels:
            if j == i:
                pass
            else: 
                count += 1
        if count == 10:
            new_word = new_word + i
        else:
            pass
    return new_word
    
print anti_vowel("codeacademy")

#3

Thank you. But, what if I wanted to print it?


#4

Then you would have to explicitly call the method, pass an argument to it. and then finally you pass it ass a token(argument ) to print

like this

anti_vowel("codeacademy")# we all the method but it is return a string value

so the only way to see that value is if we print it to console hence we call

print anti_vowel("codeacademy") # pass anti_vowel("codeacademy") as argument to print

did this clarify things for you?


#5

No....What I wanted to know is how to print certain symbols such as "¡" or "ß".


#6

Hi. I have the same problem. Codecademy test the code with the text "¡Eh, miren Palabras!". The char ¡ is given the problem.