155k views
10 votes
Write a program that reads a list of words. Then, the program outputs those words and their frequencies.

User AshD
by
7.4k points

1 Answer

5 votes

Answer:

The program in Python is as follows:

mylist = []

nword= "y"

while(nword== "y"):

word = input(": ")

mylist.append(word)

nword = input("New word: y/n: ")

for item in mylist:

freq = mylist.count(item)

print(item, freq)

Step-by-step explanation:

This creates an empty list

mylist = []

This is used to let the user input more word or stop input

nword = "y"

The following iteration lets the program read words from the user

while(nword == "y"):

This gets the user input

word = input(": ")

This appends the inputted word into the list

mylist.append(word)

This prompts if the user wants to input more word or not

nword = input("New word: y/n: ")

This iterates through the list

for item in mylist:

This gets the frequency of each word in the list

freq = mylist.count(item)

This prints the word and the frequency

print(item, freq)

User Michael Place
by
8.3k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.