Dict Practice 1

Submit solution

Points: 2
Time limit: 2.0s
Memory limit: 64M

Problem type
Allowed languages
C, C++, Python3

Mr Cleese wants to know how many times a word appears in a sentence. Your task is to help him with it.

Input Specification

The first line will contain a single English sentence. All words will be lower case and separated by a single space.

The second line will contain a single lowercased word.

Output Specification

The output should contain only integer, the number of times the inquired word has appeared in the sentence.

Sample Input 1

    canners can can what they can can .

Sample Output 1



  • 0
    Mais  commented on March 23, 2021, 8:29 a.m.

    Enter a sentence

    input_str = input()

    Enter the word you want to count

    input_word = input()

    convert the sentence in list of words

    items = input_str.split()

    initialize the count variable

    count = 0 for i in range(len(items)): if input_word == items[i]: count+=1

    print the count