Get the answers you need at Westonci.ca, where our expert community is dedicated to providing you with accurate information. Explore thousands of questions and answers from knowledgeable experts in various fields on our Q&A platform. Join our platform to connect with experts ready to provide precise answers to your questions in different areas.
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 appreciate your time on our site. Don't hesitate to return whenever you have more questions or need further clarification. Your visit means a lot to us. Don't hesitate to return for more reliable answers to any questions you may have. Get the answers you need at Westonci.ca. Stay informed by returning for our latest expert advice.