Knowee
Questions
Features
Study Tools

In the first line of input, accept a sequence of space-separated words. In the second line of input, accept a single word. If this word is not present in the sequence, print NO. If this word is present in the sequence, then print YES and in the next line of the output, print the number of times the word appears in the sequence.words = input().split('')test = input()if test not in words:    Print('No')else:    Print('YES')    count = 0    for word in words:        if test == word:            count -= 1                    Print(count)Sample Test CasesDownload All Test Case 1InputExpected OutputActual Outputa good collection of wordstheNOTest Case 2InputExpected OutputActual Outputno sentence can begin with because because because is a conjunctionbecauseYES3

Question

In the first line of input, accept a sequence of space-separated words. In the second line of input, accept a single word. If this word is not present in the sequence, print NO. If this word is present in the sequence, then print YES and in the next line of the output, print the number of times the word appears in the sequence.words = input().split('')test = input()if test not in words:    Print('No')else:    Print('YES')    count = 0    for word in words:        if test == word:            count -= 1                    Print(count)Sample Test CasesDownload All Test Case 1InputExpected OutputActual Outputa good collection of wordstheNOTest Case 2InputExpected OutputActual Outputno sentence can begin with because because because is a conjunctionbecauseYES3

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

It seems like you're asking for a Python solution to a problem where you need to check if a word is present in a sequence of words and if so, how many times it appears. Here's how you can do it:

# Accept a sequence of space-separated words
words = input().split()

# Accept a single word
test = input()

# Check if the word is in the sequence
if test not in words:
    print('NO')
else:
    print('YES')
    # Count the number of times the word appears in the sequence
    count = words.count(test)
    print(count)

This script first takes a sequence of words as input and splits them into a list. Then it takes a single word as input. It checks if this word is in the list of words. If it's not, it prints 'NO'. If it is, it prints 'YES' and then counts how many times this word appears in the list using the count method, and prints this count.

This problem has been solved

Similar Questions

Select the correct implementation of a piece of code that accepts a sentence as input and prints the number of words in it. A sentence is just a sequence of words with a space between consecutive words. You can assume that the sentence will not have any other punctuation marks. You can also assume that the input string will have at least one word.1sentence = input()2space = ' ' # there is a single space between the quotes3num_words = sentence.count(space)4print(num_words)1sentence = input()2space = ' ' # there is a single space between the quotes3num_words = sentence.count(space) + 14print(num_words)1sentence = int(input())2space = ' ' # there is a single space between the quotes3num_words = sentence.count(space)4print(num_words)1sentence = input()2num_words = len(sentence)3print(num_words)

word = input("enter a word") word = word.lower() turd = len(word) for i in range(0,turd,1): if word[i] == word[turd-i]: print("palindrome") else: print("no") palindrome()

Word CounterImplement Python program to find the number of words in a string Constraints:NAExample:Sample Input:Python Programming LanguageSample Output:3Explanation:The Number of words in the given string are 3Public Test Cases:# INPUT EXPECTED OUTPUT1 Python Programming Language3

Count the sentences, words and characters in a fileWrite a Python program that reads a file and prints the number of lines, words, and characters in the file.Input Format:The input will be a single string, which is the name of the file to be read.Output Format:The output will be three separate lines, each containing a count:The first line will contain the number of lines in the file, prefixed with "Sentences: ".The second line will contain the number of words in the file, prefixed with "Words: ".The third line will contain the number of characters in the file, prefixed with "Chars: ".Sample Test CasesTest Case 1:Expected Output:file·name:input1.txtSentences:·8Words:·34Chars:·228Test Case 2:Expected Output:file·name:input2.txtSentences:·7Words:·51Chars:·306

Why does the following code fail?word = 'alphabet'vowels = 'aeiou'count = 0while count < len(word):letter = word[count]if letter not in vowels:print(letter)count += 1

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.