Skip to content

Instantly share code, notes, and snippets.

@ebovio
Created April 16, 2017 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebovio/867b162abab97dbad0c318c40464917a to your computer and use it in GitHub Desktop.
Save ebovio/867b162abab97dbad0c318c40464917a to your computer and use it in GitHub Desktop.
#Problem9
import string
def find_bananas(file_name):
f = open(file_name,'r')
counter = 0
for line in f:
line = line.lower()
index = line.find("banana")
while index > -1:
counter +=1
index = line.find("banana",index+1)
return counter
#MainProgramBelow
print("The number of bananas in your file is", find_bananas("bananas.txt"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment