def countstring(character, filepath): myfile = open(filepath) content = myfile.read() myfile.close() return(content.count(character)) print(countstring("a", "fruits.txt"))