Question

In: Computer Science

Create a program that reports whether each word in a set of words appears in a...

Create a program that reports whether each word in a set of words appears in a paragraph. Here are the requirements: a. Ask the user to enter a set of words, one at a time. Use an appropriate prompt to keep asking for words until a blank line is entered. The set of words should be in a dictionary, where the word is the key, and “yes” or “no” is the value. The value represents whether the word appears in the paragraph. As the words are entered, the value should initially be “no”. b. Ask the user to enter a paragraph. Use an appropriate prompt to keep asking for lines/sentences of the paragraph. The lines/sentences should be in a list (of strings). When the user enters a blank line, the paragraph is complete. c. Once the paragraph is entered, check to see if each word in the dictionary is in the paragraph. If it is, then set the value of that key (word) to “yes”. It is sufficient to determine if the word is in the paragraph. You do not need to find all instances, nor count the number of instances. d. Present the results by writing the results of the dictionary using a loop. (Do not simply print the dictionary as a whole.) This should appear as two columns of data, with the key in the first column, and the corresponding value of “yes” or “no” in the second column.

Solutions

Expert Solution

Code:

import requests
url = "http://jsonplaceholder.typicode.com/todos"

class ApiHandler:
    def __init__(self):
        self.url = url

    def get_todos(self):
        try:
            result = requests.get(self.url)
            if result.status_code == 200:
                return result.response
            else:
                return None
        except TimeoutError as te:
            print('here')


    def mul(self,a,b):
        return a*b


words = {} # initialize the words dict
print("Continue entering words and stop with input as blank word")
while True:
    word = input() # input single word
    if word: # if input is present that is not a blank line then add to dict
        words[word] = 'no' #initialize
    else:
        break

lines = []
print("Continue entering lines and stop with input as blank line")
while True:
    line = input()
    if line:
        lines.append(line)   # adding input in list lines
    else:
        break

for word in words: # for each word in the dict words
    for line in lines: #for each lines in the list lines
        if word in line: # if line has the word then then store dict[key] = "yes" then break as we don't want countor anything as such in the paragraph
            words[word] = 'yes'
            break

for word in words:
    print(word + "\t" + words[word]) # print the word and the value i.e yes/no

Screenshot of the code:

Output:


Related Solutions

Suppose that you are given a set of words; and two words from the set: word...
Suppose that you are given a set of words; and two words from the set: word 1 and word 2. Write a program which will transform word 1 into word 2 by changing a single letter in word 1 at a time. Every transition that word 1 takes will have to be in the set of words. You must output the smallest sequence of transitions possible to convert word 1 into word 2. You may assume that all the words...
State whether each of the following events appears to be the result of a shift in...
State whether each of the following events appears to be the result of a shift in short?run aggregate supply or aggregate demand, and state the direction of the shift involved. a) The price level rises sharply while real GDP falls. b) The price level and real GDP rise. c) The price level falls while real GDP rises. d) The price level and real GDP fall. To the Tutor: Please be clear and explanatory. Will be appreciated. Thank you.
Create a program (or set of programs) which accomplish the following for each complex data type...
Create a program (or set of programs) which accomplish the following for each complex data type (list,tuple,set,frozenset, dictionary): create the item with at least 4 elements Append an element Remove an element Insert an element in the middle somewhere Append another array of the same data type Append another array of a different data type (for example, if you have a dictionary, append a set or tuples And do the following: Output the results after each step. Report and explain...
Create a program (or set of programs) which accomplish the following for each complex data type...
Create a program (or set of programs) which accomplish the following for each complex data type (list,tuple,set,frozenset, dictionary): create the item with at least 4 elements Append an element Remove an element Insert an element in the middle somewhere Append another array of the same data type Append another array of a different data type (for example, if you have a dictionary, append a set or tuples And do the following: Output the results after each step. Report and explain...
Create a program that accepts in a string of 2 or more words. The program then...
Create a program that accepts in a string of 2 or more words. The program then copies the entered string changing the alpha characters into digits representing characters with acsenders, descenders and nonascender/desender characters; uppercase characters should be treated as lower case. The characters with descenders (gjpqy) should be replaced with a 1. The characters with ascenders (dbfhklt) should be replaced with a 2. The rest of the alpha characters should be replaced with a 3. The converted string should...
Create a program in C that counts the number of characters in a word when a...
Create a program in C that counts the number of characters in a word when a user inputs a string. Use stdin to read an input string. For example, if a user inputs: “The dog is good” the output should be a= [The], b=3 a= [dog], b=3 a= [ is], b=2 a= [good], b=4 a= [ ], b=0000 Take into account EOF. If an EOF is reached at the end of the string then the output should be 0000. (example...
Create a program in C that counts the number of characters in a word when a...
Create a program in C that counts the number of characters in a word when a user inputs a string. Use stdin to read an input string. For example, if a user inputs: “The dog is good” the output should be a= [The], b=3 a= [dog], b=3 a= [ is], b=2 a= [good], b=4 a= [ ], b=0000 Take into account EOF. If an EOF is reached at the end of the string then the output should be 0000. (example...
Write a program that reads a text file and reports the total count of words of...
Write a program that reads a text file and reports the total count of words of each length. A word is defined as any contiguous set of alphanumeric characters, including symbols. For example, in the current sentence there are 10 words. The filename should be given at the command line as an argument. The file should be read one word at a time. A count should be kept for how many words have a given length. For example, the word...
Write a program in JAVA to create the move set of a Pokémon, and save that...
Write a program in JAVA to create the move set of a Pokémon, and save that move set to a file. This program should do the following: Ask for the pokemon’s name. Ask for the name, min damage, and max damage of 4 different moves. Write the move set data into a file with the pokemon’s name as the filename. The format of the output file is up to you, but keep it as simple as possible
Create a C program that solves the word search puzzle contained in the file 'WordSearchPuzzle.txt'. The...
Create a C program that solves the word search puzzle contained in the file 'WordSearchPuzzle.txt'. The words that need to be found are in the file 'WordList.txt'. There are 100 words to be found. You must find the location of the first and last letter of each word as well as the cardinal direction that describes the word's orientation. The location of first and last letters are to be described in terms of row and column, with indexing starting at...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT