Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help understanding why my program in python isn't displaying results. If somebody could fix the code or explain to me what I have

I need help understanding why my program in python isn't displaying results. If somebody could fix the code or explain to me what I have to do.Thanks

image text in transcribed

image text in transcribed

Fidef read_list(): Acreating an empty list words_list = 0) Hopening the file file = open ("TextFilei.txt") Areading the context of the file context_of_file = file.readline() we have to split the words into the empty list we created before words_list = Context_of_file() Aclosing the file and returning the context of the file into the list now file.close() return words_list Edef write(words_list): Acounts how many times a word is shown file.open('TextFilei.count.txt') Awe are now going to sort the list it will be shown alphabetically words_list.sort() Musing the zero will allow to get the first word in file repeat_word = words_list[@] count = 0 Ngoing through words, gonna skip or add to the same word for i in range (len(words_list)): x=words_list[1] Awill tell if the word is the same or not if x==repeat_word: count=count+1 #creating the writing for the output of the same word else: file.wirte (repeat_word) file.wirte(':') file.wirte(str(count)) file. wirte(" ') repeat_wordex count=1 this next else statment is for output of the different word else: file.write(repeat_word) file.write(':') f.write(str(count)) f.write(" ") #closing file complety closed due to it not being needed anymore file.close() Acreating the main function now. Eldef main(): words_list = [] words_list = read_list() print (words_list) if name main": main() TextFile1.txt PythonApplication 1.py + X A write C:\Users\justr\AppData\Local\Programs\Python Python39\python.exe Press any key to continue . . Fidef read_list(): Acreating an empty list words_list = 0) Hopening the file file = open ("TextFilei.txt") Areading the context of the file context_of_file = file.readline() we have to split the words into the empty list we created before words_list = Context_of_file() Aclosing the file and returning the context of the file into the list now file.close() return words_list Edef write(words_list): Acounts how many times a word is shown file.open('TextFilei.count.txt') Awe are now going to sort the list it will be shown alphabetically words_list.sort() Musing the zero will allow to get the first word in file repeat_word = words_list[@] count = 0 Ngoing through words, gonna skip or add to the same word for i in range (len(words_list)): x=words_list[1] Awill tell if the word is the same or not if x==repeat_word: count=count+1 #creating the writing for the output of the same word else: file.wirte (repeat_word) file.wirte(':') file.wirte(str(count)) file. wirte(" ') repeat_wordex count=1 this next else statment is for output of the different word else: file.write(repeat_word) file.write(':') f.write(str(count)) f.write(" ") #closing file complety closed due to it not being needed anymore file.close() Acreating the main function now. Eldef main(): words_list = [] words_list = read_list() print (words_list) if name main": main() TextFile1.txt PythonApplication 1.py + X A write C:\Users\justr\AppData\Local\Programs\Python Python39\python.exe Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

What is Accounting?

Answered: 1 week ago

Question

Define organisation chart

Answered: 1 week ago

Question

What are the advantages of planning ?

Answered: 1 week ago

Question

Explain the factors that determine the degree of decentralisation

Answered: 1 week ago