-
Notifications
You must be signed in to change notification settings - Fork 9
/
ex_09_4_2.py
30 lines (26 loc) · 808 Bytes
/
ex_09_4_2.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
#!/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.4
# Can you make a sentence using only the letters acefhlo?
# Other than Hoe alfalfa?
def uses_only(word, string):
for letter in word:
if letter not in string:
return False
return True
string = 'acefhlo'
fin = open('words.txt')
count = 0
for line in fin:
word = line.strip()
if word != 'hoe' and word != 'alfalfa':
if uses_only(word, string):
count +=1
print(word)
print('You have {} words which contain only "acefhlo" letters to make a sentance.'.format(count))
# This code returns
#END