Mar-16-2021, 12:27 AM
In python,
for word in dataSplit :will iterate over every word in the data, so...
def searchText (): print("Please enter a word that will be used to search a text file") search_word = input() textFile = open ('assignment8.txt', "r") data = textFile.read() dataSplit = data.split () count = 0 for word in dataSplit : if word == search_word : count = count + 1 print (count) searchText ()will count every occurrence of the search word. You almost had it.