Question

In: Computer Science

Write the simplest program possible in your language of choice containing your 'main' and any other...

Write the simplest program possible in your language of choice containing your 'main' and any other functions you may need that will:

A. Read a sequence of words up to a maximum of 64 words from std input. Before reading the input, prompt the user to enter the words.

B. Check to see if there any duplicate words in the input read.

C. If there are no duplicates, print out to std output the message 'No Duplicates'.

D. If there are duplicates, print out on separate lines each word that is duplicated and the number of instances of that word. The results should be sorted in ascending

E. If you write helper functions to your main, ensure that all input and output happens only in main.

F. Do not use Vectors, Collections, or any other data structures provided by the language platform or any oft-used third party libraries like STL.

G. Take screenshot of your program execution with the following samples.

H. Your program will be tested with my own input.

Sample Inputs Sample Outputs
THE RAIN IN MAINE. No Duplicates
THE RAIN IN MAINE IN THE MONTH OF MAY.

IN 2

THE 2

The rain in Maine in the month of May. in 2
The rain in Maine in the month of May makes May the rainiest month for Maine in the year.

Maine 2

May 2

in 3

month 2

the 3

Please do it in Python

Solutions

Expert Solution

Hi,

Hope you are dong fine. I have coded the above question in python as per your requirements. I have tried to keep it as simple as possible. I have not used or imported the collections module or any other external modules to write the code. The code has been clearly explained using comments that have been highlighted in bold. Also have a look athe snippets from the editor for correct indentation.

Program:

#Taking input from user. It is stored as a string
string=input()
#removing the fullstop at the end because, is a duplicate is present at the end, then the full stop along with it will be difficult for comparison
string=string.strip(".")
#split the words seperated by space and store then in a list called words
words=string.split(" ")
#if the number of words are more than 64 then
if len(words)>64:
#reduce the size of the words list upto the first 64 words
words=words[:64]
#count is an empty dictionary
count={}
#flag is used to check if there are any duplicates present. It is set to one if atleast one duplicate is found
flag=0
#dupes stores the list of duplicates
dupes=[]
#taking x as key and assigning value 0 to every element of count from words
for x in words:
count[x]=0
#traversing the list of words
for x in words:
#increment count in dictionary for each word
count[x]+=1
#traversing the dictionary to check the values of each key i.e word
for x in count:
#if count is more than 1, it means that it is a duplicate
if count[x]>1:
#append it to the list of dupes
dupes.append(x)
#set flag to 1
flag=1
#if flag is 0, then it means that there are no duplicates
if flag==0:
print("No Duplicates")
else:
#sort the duplicates in ascending order
dupes.sort()
#traversing and printing the duplicates ine by line
for x in dupes:
print("{} {}".format(x,count[x]))

Executable code snippet:

Sample outputs: Note that first line is the input.


Related Solutions

Write a program in MIPS assembly language to convert an ASCII number string containing positive and...
Write a program in MIPS assembly language to convert an ASCII number string containing positive and negative integer decimal strings, to an integer. Your program should expect register $a0 to hold the address of a nullterminated string containing some combination of the digits 0 through 9. Your program should compute the integer value equivalent to this string of digits, then place the number in register $v0. If a non-digit character appears anywhere in the string, your program should stop with...
Write a program, using any language you want, and any sorting algorithm discussed in this unit...
Write a program, using any language you want, and any sorting algorithm discussed in this unit to sort the following : 243, 1, 4, 6, 234, 33, 674, 32, 3333 Note: Can you write it in quick sort
Write a program using C language that -ask the user to enter their name or any...
Write a program using C language that -ask the user to enter their name or any other string (must be able to handle multiple word strings) - capture the epoch time in seconds and the corresponding nanoseconds - ask the user to type in again what they entered previously - capture the epoch time in seconds and the corresponding nanoseconds -perform the appropriate mathematical calculations to see how long it took in seconds and nanoseconds (should show to 9 decimal...
Language Python with functions and one main function Write a program that converts a color image...
Language Python with functions and one main function Write a program that converts a color image to grayscale. The user supplies the name of a file containing a GIF or PPM image, and the program loads the image and displays the file. At the click of the mouse, the program converts the image to grayscale. The user is then prompted for a file name to store the grayscale image in.
Write 5 smart goals in any company of your choice
Write 5 smart goals in any company of your choice
Write an assembly language program that will print out the message of your choosing #NOTE #write...
Write an assembly language program that will print out the message of your choosing #NOTE #write in a simple way, so that i can execute it from command window using masm
using Visual Studio write a code containing a main() program that implements the coin change state...
using Visual Studio write a code containing a main() program that implements the coin change state machine in C++ according to the guidance given in Translating a state machine to C++ Test your code using prices 1 and 91 cents, and assume change is calculated from a dollar bill. Copy and paste your console output to a text editor and save the result in a single file named console.txt. Upload your exercise081.cpp and console.txt files to Canvas.
Investigate and report the main safety issues emphasized in a country of your choice other than...
Investigate and report the main safety issues emphasized in a country of your choice other than the United States. You can search the internet for this exercise or find a case described in a scholarly article. Using OSHA regulations as a guide, determine what the accepted safety standards are for the above issues.
Assignment Write a program using turtle graphics which writes your initials, or any other three unique...
Assignment Write a program using turtle graphics which writes your initials, or any other three unique letters, to the display. Look to your program for lab 1 for reminders of how to use turtle graphics. Functions that must be written: def drawLetter (x, y, letterColor): Write three functions, one for three unique letters. Personally, I would write drawA, drawR, and drawS. Each function must draw that letter to the screen. The x and y values determine the upper left-hand location...
Write a program with an array that is initialized with test data. Use any primitive data type of your choice. The program should also have the following methods:
IN JAVA Array Operations Write a program with an array that is initialized with test data. Use any primitive data type of your choice. The program should also have the following methods: getTotal: This method should accept a one-dimensional array as its argument and return the total of the values in the array. getAverage: This method should accept a one-dimensional array as its argument and return the average of the values in the array. getHighest: This method should accept a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT