Answer :
Answer:
The solution in Python is as follows:
str = "sample.txt"
a_file = open(str, "r")
words = []
for line in a_file:
stripped_line = line.strip()
eachlist = stripped_line.split()
words.append(eachlist)
a_file.close()
word_list= []
n = int(input("Number of words: "))
for i in range(n):
myword = input("Enter word: ")
word_list.append(myword)
for rn in range(len(word_list)):
index = 0; count = 0
print()
print(word_list[rn]+": ",end = " ")
for i in range(len(words)):
for j in range(len(words[i])):
index+=1
if word_list[rn].lower() == words[i][j].lower():
count += 1
print(index-1,end =" ")
if count == 0:
print("Word not found")
Explanation:
See attachment for complete program where comments are used to explain difficult lines