Read a string with words separated by space and return its length and count of consonants.Sample Inputwrite a programSample Output158
Question
Read a string with words separated by space and return its length and count of consonants.Sample Inputwrite a programSample Output158
Solution
Sure, here is a Python solution for your problem:
def count_consonants_and_length(input_string):
consonants = "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ"
length = len(input_string)
consonant_count = sum(1 for char in input_string if char in consonants)
return length, consonant_count
input_string = "write a program"
length, consonant_count = count_consonants_and_length(input_string)
print(length, consonant_count)
This program defines a function count_consonants_and_length that takes an input string, counts its length and the number of consonants in it. The consonants are defined in the consonants string. The function then returns the length of the string and the count of consonants.
The input string "write a program" is passed to this function, and the results are printed.
Similar Questions
IPS5-Pointer5Read a string with words separated by space and return its length and count of consonants.Sample Inputwrite a programSample Output158
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
letter countWrite a C program that will analyze a line of text and will print the number of words, the number of consonants, and the number of vowels in the text.Testcase:Input:Programming is fun!Output:3 // Number of words:11 // Number of consonants:5 // Number of vowels:
find the number of alphabet vowels and words in input using string
Write a program in C to count the number of vowels and consonants in a string. You can use fgets to read the characters.
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.