May-22-2018, 10:30 PM
Help please!
I am starting to learn python using the ThinkPython book. For exercise 9.2, I wrote the below code (which is the same as the answer code posted online). However, the conditional statement only recognizes the first letter. For example, if the word starts with the letter 'e' or 'E' (such as "elephant"), the statement returns False and for all others, including words containing the letter 'e' or 'E' but not at the beginning (such as "love"), the statement will return True. Can someone please point it out to me what I am doing wrong? Thank you very much!!
I am starting to learn python using the ThinkPython book. For exercise 9.2, I wrote the below code (which is the same as the answer code posted online). However, the conditional statement only recognizes the first letter. For example, if the word starts with the letter 'e' or 'E' (such as "elephant"), the statement returns False and for all others, including words containing the letter 'e' or 'E' but not at the beginning (such as "love"), the statement will return True. Can someone please point it out to me what I am doing wrong? Thank you very much!!
fin=open('words.txt') def has_no_e(word): char="" for char in word: if char == 'E' or char == 'e': return False return True