"""=====================
exercise 9.2
====================="""
def has_no_e(word):
char = ""
for char in word:
if (char == "E") or (char == "e"):
return False
return True
fin = open('words.txt')
total_words = 0
words_without_e = 0
percent_without_e = 0.0
for line in fin:
word = line.strip()
if has_no_e(word):
print word
words_without_e = words_without_e + 1
total_words = total_words + 1
percent_without_e = ( words_without_e / total_words ) * 100
Hi, I run the program but it didn't work.
ReplyDeleteRun it, and add print(word) before c2=c2+1 if you want the list of words without e as well.
ReplyDeletefin= open('words.txt')
c1=0
c2=0
for line in fin:
line=fin.readline()
word=line.strip()
c=0
c1=c1+1
for letter in word:
if letter=='e':
c=c+1
if c<1:
c2=c2+1
print(((c1-c2)/c1)*100)
Run it, and add print(word) before c2=c2+1 if you want the list of words without e as well.
ReplyDeletefin= open('words.txt')
c1=0
c2=0
for line in fin:
line=fin.readline()
word=line.strip()
c=0
c1=c1+1
for letter in word:
if letter=='e':
c=c+1
if c<1:
c2=c2+1
print(((c1-c2)/c1)*100)
This comment has been removed by the author.
ReplyDeletewhat do you think about my solution :
ReplyDelete# thinkpython2 python version 3.5
# the solution of the exercice n° 9.2
i=0
j=0
fin = open('words.txt')
for line in fin:
____word = line.strip()
____j=j+1 # j is the total number of words in th text file
____if 'e' not in word :
________print(word)
________i=i+1 # is the total number of the letter e in the text file
print(i*100/j,"%")