# Tutorial 3 - Problem 7 def count(word, targetLetter): count = 0 for letter in word: if letter == targetLetter: count = count + 1 return count # As a second exercise, rewrite the function so that instead of traversing the string, # it uses the three parameter version of find from our Problem 4. def findStartingAt(word, letter, startingHere): # For testing purposes # print(word, letter, startingHere) index = startingHere position = -1 while index < len(word): if word[index] == letter: # For testing purposes # print(word, letter, startingHere, index) position = index index = len(word) else: index = index + 1 return position def count2(word, targetLetter): count = 0 index = 0 while index != -1: index = findStartingAt(word, targetLetter, index) if index != -1 : count += 1 index += 1 return count # Main part of program print('count("Greetings all Ladies of Bample", "a")): ', count("Greetings all Ladies of Bample", "a")) print('count2("Greetings all Ladies of Bample", "a")): ', count2("Greetings all Ladies of Bample", "a"))