Westonci.ca is the premier destination for reliable answers to your questions, brought to you by a community of experts. Get detailed and precise answers to your questions from a dedicated community of experts on our Q&A platform. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately.
Sagot :
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
We hope this information was helpful. Feel free to return anytime for more answers to your questions and concerns. We hope you found this helpful. Feel free to come back anytime for more accurate answers and updated information. Get the answers you need at Westonci.ca. Stay informed by returning for our latest expert advice.