Exercise 73

Write a python function that takes a string 's' as parameter and which delete all vowels from the string 's'. Example: if s = "Python is hight level programming language", the algorithm returns the string: "Pthn s hght lvl prgrmmng lngg"

Solution

def remove_vowels(s):
    # define all vowels in the following string:
    vowels = "AEYIOUaeyiou"

    # initialize an empty string result that will be used to build the final string without vowels.
    result = ""

    # we then loop through each character in the input string s
    for char in s:
        if char not in vowels:
            result += char
    return result

# Example of use of this algorithm:
s = "Python is hight level programming language"
result = remove_vowels(s)
print(result)
#output: 'Pthn s hght lvl prgrmmng lngg'




 

Younes Derfoufi
my-courses.net

One thought on “Solution Exercise 73: python algorithm that remove all vowels from a given string”

Leave a Reply