Knowee
Questions
Features
Study Tools

Write a program to count number of words in a given string whose length is greater than 3.For example:Input Resultpython is easier than C3

Question

Write a program to count number of words in a given string whose length is greater than 3.For example:Input Resultpython is easier than C3

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

Solution

Sure, here is a Python program that counts the number of words in a given string whose length is greater than 3.

def count_words(string):
    # Split the string into words
    words = string.split()
    
    # Initialize a counter
    count = 0
    
    # Iterate over the words
    for word in words:
        # If the length of the word is greater than 3, increment the counter
        if len(word) > 3:
            count += 1
            
    # Return the count
    return count

# Test the function
print(count_words("python is easier than C"))

When you run this program with the input "python is easier than C", it will output 3, because the words "python", "easier", and "than" all have more than 3 characters.

This problem has been solved

Similar Questions

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

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)

Read a string with words separated by space and return its length and count of consonants.Sample Inputwrite a programSample Output158

Raghu's tutor provides him a simple sentence and asks him to count the number of words in the sentence. The words are separated by space.Example, if the tutor provides the sentence as "Welcome to Java", the output should beNumber of words 3The words are WelcometoJavaFill the space in the below code so that the code fulfills his requirement. Code :                Scanner sc=new Scanner(System.in); String str=sc.nextLine(); String words[ ]  =   ; int count=  ;  //count holds the number of words in the sentence System.out.println("Number of words "+); System.out.println("The words are "); for(String    :     ) //for each loop System.out.println(x);

Write a program to accept a string as input and print the number of consonants in the string.Input:StringOutput:IntegerConstraints1<=length of string <=1000

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.