187k views
1 vote
Here's something to stop you from getting repetitive when writing essays. Write a program that reads multiple lines of plain text from the user, then prints out each different word in the input with a count of how many times that word occurs. Don't worry about punctuation or case – the input will just be words, all in lower case. Your output should list the words in alphabetical order.

1 Answer

1 vote

Answer:

The output is attached below

Step-by-step explanation:

d = {}

while True:

line = input("Enter line: ")

if len(line)==0:

break

token = line.split(' ')

for var in token:

try:

if len(var)==0:

continue

count = d[var]

d[var] = count + 1

except KeyError:

d[var] = 1

pass

for word in sorted(d):

print(word , d[word])

------------------

Here's something to stop you from getting repetitive when writing essays. Write a-example-1
User David Schilling
by
4.3k points