8/15 anti_vowel


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<In what way does your code behave incorrectly? Include ALL error messages.>

The error message says:
Your function fails on anti_vowel(“Hey look Words!”). It returns “None” when it should return “Hy lk Wrds!”.
<What do you expect to happen instead?>

But I used print to print those out, may I know the use of return here? If I am not going to use the output of the function again, would it matter if I don’t return the result? I am new to programming and Python and very frustrated right now…

```python
<do not remove the three backticks above>

(initial one)
def anti_vowel(text):
  lst = 'aeiouAEIOU'
  result =[]
  for n in text:
    if n not in lst:
      result.append(n)
  print "".join(result)

(corrected one)
def anti_vowel(text):
  lst = 'aeiouAEIOU'
  result =[]
  for n in text:
    if n not in lst:
      result.append(n)
  print "".join(result)
  return "".join(result)

#2

The exercise asks you to return the anti vowel string, as such you are expected to meet exercise criteria

the other thing is that if we return the anti vowel string, means that we can get access to the anti vowel string in other parts of our program (global or other functions). Although currently not present, its a really good program design to use return here.

Codecademy teaches you this concept, otherwise a poor concept would be taught, which is what no one wants


#3

Got it. Thank you very much.:blush::blush:


#4

When i started programming, i had the same thing, i was like: why do i need to return, who cares? Now i am grateful i did, this better habits (using return) save you a lot of pain later.

I have come to see the value of defensive coding (what if i need to change this later, or another developer is taking over?). Same here, what if this function is needed later in another program? Then return certainly will be better. Or this program might need to be extended later.

You will notice this later hopefully as well, maybe not yet, given this is just one small function. Hope this answered your question and takes away some of that frustration :slight_smile:


#5

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