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
python is easier than C3
Result

🧐 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

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

Word CounterImplement Python program to find the number of words in a string Constraints:NAExample:Sample Input:Python Programming LanguageSample Output:3

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

Write a Python program to count the number of occurrences of a specific character in a string

Give a regular expression for all strings whose length is strictly greater than 3.

1/2

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.