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 a language of your choice to perform a search using the A*...
Write a program in a language of your choice to perform a search using the A* algorithm for the eight puzzle problem, in which numbers may be shifted one space at a time to transform the initial state into the goal state (see p. 103 – 3rd Ed., pp. 105-106 – 2nd Ed. of the text). 2. a) Use the start state-goal state combination given in pp. 103, Figure 3.28 (3rd Ed.), [pp. 105, Figure 4.7 (2rd Ed.)], as (start_1,...
Using a programming language of your choice, write a complete and fully functional program that uses...
Using a programming language of your choice, write a complete and fully functional program that uses reference and pointer types to swap two double precision floating-point numbers. The two numbers are read in by the program’s user. Use a proper prompt for each number. Use one function that uses formal parameter reference types to swap the two numbers Use another function that uses formal parameter pointer types to swap the two numbers. In the main or driver function, call these...
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
This is all that was given. Write a program in a PL of your choice to...
This is all that was given. Write a program in a PL of your choice to create the followings Output: A table(7 rows), you see below, showing 35 names grouped in 7 lines. The first column is the chosen Programming Language to develop and present by the group. PLs All group Names C n26 n06 n28 n16 n30 C++ n31 n07 n33 n17 n35 C# n03 n08 n13 n18 n23 Python n04 n09 n14 n19 n24 java n05 n10 n15...
Write 5 smart goals in any company of your choice
Write 5 smart goals in any company of your choice
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...
1. Write a program that does the following. Write in Assembly Language program Loads your student...
1. Write a program that does the following. Write in Assembly Language program Loads your student ID number into memory starting at location 0x2000 0100 a. DO NOT do any conversion on your ID number. If my ID number is 123456789, I should be able to read your ID in memory as 123456789 2. Loads the first six characters of your name, in ASSIC, in to memory right after your student ID. Total of 6 bytes. a. This means that...
. Write a C program that asks the user a multiple-choice question and shows four possible...
. Write a C program that asks the user a multiple-choice question and shows four possible answers, (a) through (d). Prompt the user to input a response as a character. If the user enters the correct response, print a message stating that the answer is correct. If the user enters an incorrect response, print a message stating that the answer is wrong. If the user enters anything other than the letters a, b, c, or d, print a message stating...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT