-
Notifications
You must be signed in to change notification settings - Fork 9
/
ex_09_5.py
35 lines (28 loc) · 940 Bytes
/
ex_09_5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python
#AUTHOR: alexxa
#DATE: 27.12.2013
#SOURCE: Think Python: How to Think Like a Computer Scientist by Allen B. Downey
# http://www.greenteapress.com/thinkpython/html/index.html
#PURPOSE: Chapter 9. Case study: word play
# Exercise 9.5
# Write a function named uses_all that takes a word and
# a string of required letters, and that returns True if
# the word uses all the required letters at least once.
# How many words are there that use all the vowels aeiou?
# How about aeiouy?
def uses_all(word, string):
for letter in string:
if letter not in word:
return False
return True
def vowels(string):
fin = open('words.txt')
count = 0
for line in fin:
word = line.strip()
if uses_all(word, string):
count +=1
print('There are {} words which contain all "{}" letters at once.'.format(count,string))
vowels('aeiou')
vowels('aeiouy')
#END