Created
October 11, 2017 12:57
-
-
Save lornamariak/0311e2e14b8d29f69ba534da80767fc3 to your computer and use it in GitHub Desktop.
COUNTING NUMBER OF VOWELS IN A SENTENCE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x <- readline(prompt = "Enter Sentence: " ) # Ask user to enter word or sentence | |
#split the sentence into characters and store them as list | |
sentence = as.list(strsplit(x, "" )[[1]]) | |
vowels = list("a","e","i","o","u") # store vowels as a list | |
# check for vowels in the sentence and print TRUE for every vowel found | |
print( vowels %in% sentence ) | |
# print the letters that appear in the vowel list and sentence list | |
print((intersect(vowels,sentence))) | |
# print the length of the string in line 8 which is the number of vowels present | |
print(length((intersect(vowels,sentence)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment