Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The string " car " contains 1 vowel(s).
- import sys
- wordlist = ['hat', 'book', 'house', 'flower', 'tree', 'grass', 'cheEtah', 'lion', 'tiger', 'car', 'boat']
- #for loop is used to iterate over list, in our case 11 times
- for index in range(len(wordlist)):
- #if condition is checked because we have to every third element of the list if the list is starting from 0th position
- if index%3 == 0:
- #This will help you to iterate over a single element of the list
- word = wordlist[index]
- #A counter is defined so that its value can be incremented whenever a vowel is found
- count = 0
- #for loop is used to iterate over every alphabet of element and find which one is a vowel and since the ASCII value of 'a' and 'A' is different that is why both cases are considered.
- for i in range(len(word)):
- if word[i] in {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'}:
- count += 1
- print ('The string "',word,'" contains',count,'vowel(s).')
- #If the string would contain 3 or more vowels than it will exit from the system and further element's vowels will not be calculated.
- if count >= 3:
- print ("***Found string with 3 or more vowels!***")
- sys.exit(0)
- #If we will not found any string with 3 or more vowels than at the end of program the print statement will print else not.
- print ("***Did not find suitable string.***")
- #Output is:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement