0

This is my current program that replaces vouls in to nothin(cs50 program)

user_input = input("Input: ")
for letter in user_input:
 if (letter == 'a' or letter == 'e' or letter == 'i' or letter == 'o' or letter == 'u'):
    print(user_input.replace("a", "").replace("e", "").replace("i", "").replace("o", "").replace("u",""))

and I would like to know if there is a way to make it less repetitve and more stream line because I have no clue how to do that, and it has a bug where it prints the output more times than it should, and I don't know what causes that

  • 2
    You are not checking it propperly. If letter == 'a' or letter == 'b' or letter == 'c: user_input.replace(letter, '') This way you will change the letter that matches 'a', 'b' or 'c'. – Jose M. González Jul 04 '23 at 12:03
  • The reason why it prints the input multiple times is that you're printing the replaced user_input, not the letter. – Monata Jul 04 '23 at 12:03
  • 3
    To spell it out more clearly, the second answer in the question posted above can be used for this: `user_input.translate(str.maketrans('','', 'aeiou'))` to remove these vowels – Homer512 Jul 04 '23 at 12:04

0 Answers0