Exercise 8/15 anti_vowel - Practice Makes Perfect

python

#1

I am being so dense with this problem. I can’t work out why my solution doesn’t work. I thought this was simple and I’d learned to understand the language taught so far! Seems to be a problem with my appending, can you not append characters in a string word? Should I be making a new list that separates each character and then delete or remove the vowels from the list of separate characters and then re-attach the individual letters? That seems a bit long-winded…

It is throwing up the error:

Your code looks a bit off–it threw a “‘str’ object has no attribute ‘append’” error. Check the Hint if you need help!

def anti_vowel(text):
  no_vowel = ""
  rubbish = ""
  for char in text:
    if char in "aeiouAEIOU":
      rubbish.append(char)
  else:
      no_vowel.append(char)
  return no_vowel

#2

.append() is a method belonging to list, if you want to add to a string use +


#3

thank you for such a quick reply. Like this?

def anti_vowel(text):
  no_vowel = ""
  rubbish = ""
  for char in text:
    if char in "aeiouAEIOU":
      rubbish + (char)
  else:
      no_vowel + (char)
  return no_vowel

I have another error but at least the function is actually following through now!

Your function fails on anti_vowel(“Hey look Words!”). It returns “” when it should return “Hy lk Wrds!”.


#4

Some playing and I finally twigged it! Thank you for leading me to the solution, I was completely lost.

def anti_vowel(text):
  no_vowel = ""
  rubbish = ""
  for char in text:
    if char in "aeiouAEIOU":
      rubbish += char
    else:
      no_vowel += char
  return no_vowel

#5

well, you could also have opted to use .append() by changing no_vowel in rubbish into a list, then after the loop use .join()

is the not keyword not covered yet? That could save you some lines

Its my answer style, i push in the right direction, the less i do the more you learn (weird as that may sound), i only reminded you about how to concat a string, you had to figure out how to update the variable, something you learned, and by releasing this yourself, you learned more then if i would have just told you :wink:


#6

Aaaah this is fantastic! I completely understand now! I went back and tried out what you’re saying. This code with append also solves it:

def anti_vowel(text):
  no_vowel = []
  rubbish = []
  result = ""
  for char in text:
    if char in "aeiouAEIOU":
      rubbish.append(char)
    else:
      no_vowel.append(char)
  return result.join(no_vowel)

and yes, the not keyword was covered in the battleship section and this code also works and i THINK that’s as short as I can make it.

def anti_vowel(text):
  no_vowel = ""
  for char in text:
    if char not in "aeiouAEIOU":
      no_vowel += char
  return no_vowel

This has been so helpful, I feel like I’m learning! Haha, thank you again!!


#7

for now, yes :slight_smile:

yep, this section (practice makes perfect) really start going towards programming. So far, most exercises are coding (reading and typing over from instructions), now you really have to design the program :slight_smile:


#8

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