Counting total number of consonants in a string in recursive way using Python (Google Interview Question)

viowels = 'aeiou'
def recursive_consonants(string):
    if string == '':
        return 0
    if string[0].lower() not in viowels and string[0].isalpha():
        return 1+recursive_consonants(string[1:])
    else:
        return recursive_consonants(string[1:])
print(recursive_consonants('Sayan'))

Leave a comment