Anti_vowel issues a mistake without reason


#1

Hi everyone, I wanna coding “anti_vowel” like the “reverse” part. It runs wrong without reason however. Could anyone tell me about it? Thanks a lot

def anti_vowel(text):
  word = ""
  a = len(text) - 1
  while a >= 0:
    if text[a] in "aeiouAEIOU":
      a -= 1
    else:
        word += text[a] 
  return word 

#2

looks like you have have an infinity loop, a always need to decrease, otherwise the loop condition won’t become false


#3

I guess maybe the blank space between string cause it? Dose anyone know about it?


#4

no, you have an infinity loop. Add a function call and a print statement inside the loop and you will see

for a consonant a variable is not decreasing, so a will stay the same value forever when the first consonant is encountered by the loop


#5

Thanks for answer! It dose. Already tried and got it .


#6

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