Python Interview Questions - Counting syllables from a given string

 



Questions:
Define a function named count that takes a single parameter. The parameter is a string. The string will contain a single word divided into syllables by hyphens, such as these:
"ho-tel"
"cat"
"met-a-phor"
"ter-min-a-tor"
Your function should count the number of syllables and return it.
For example, the call count("ho-tel") should return 2.


Code:
def count(a):
    count = 1
    for i in a:
        if i == '-':
           count = count + 1
    return count
a = "met-a-phor"
out = count(a)

Output:



Comments