Replacing Vowels with Asterisks

Category: Python Basics

Write a program that asks the user to input a string and then outputs the string with all vowels replaced by asterisks (*).

Example:

Input: "Hello, World!" 

Output: "H*ll*, W*rld!"

Input: "Python Rocks" 

Output: "Pyth*n R*cks"

You can iterate through the string, replacing each vowel with an asterisk. Remember to consider both uppercase and lowercase vowels.

def replace_vowels(s):
vowels = 'aeiouAEIOU'
return ''.join('*' if char in vowels else char for char in s)

input_string = input("Enter a string: ")
output_string = replace_vowels(input_string)
print(output_string)

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!