d_vwlDecember 19, 2016
A quick note on
return is how a function gives back a value. This value is often unseen by the human user, but it can be used by the computer in further functions.
On a more expansive note,
Print is for people. Remember that slogan. Printing has no effect on the ongoing execution of a program. It doesn’t assign a value to a variable. It doesn’t return a value from a function.
Remove the Vowels
In repl, go to de_vowel
Create a function,
de_vowel, which will take a string as input and return a copy of that string with all the vowels removed. Otherwise, the string should be the same.
- Create the function contract for
def de_vowel(string): """ A function contract explains what the function does. So, in this case, yours might look like: #This function takes a string as an input and returns a copy of the string with the vowels removed. Write `de_vowel` using a for loop Provide a few examples that confirm de_vowel works as expected: * What if the string is all vowels ('aeiou')? * What if there are no vowels ('rdcls')? * What if some of the vowels are capital and some are lowercase ('lIKe ThIs?') * What if there is a mix of vowels and non-vowels and spaces ('this is silly')? """
def de_vowel(a_string): # your code goes here no_vowels = de_vowel("This sentence has no vowels") print(no_vowels) # examples go here
Review Adding Strings
Now, before your
d_vwl‘d sentence, add a string explaining what’s happening. Like this:
Here is your sentence without vowels: Hr s yr sntnc wtht vwls
Use a counter (variable you define outside of a loop to keep track of a value inside a loop) to create a function
count_vowels takes in a string and returns an int representing the number of vowels in the string.