Anti_vowel issues a mistake without reason


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
        word += text[a] 
  return word 


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


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


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


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


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