Suppose there are two players Amal and Bimal. They are playing a game. The game rules are as follows −
Both players have a same string s.
Both of them have to make substrings using the letters of s.
Bimal has to make words starting with consonants.
Amal has to make words starting with vowels.
The game will end when both players have made all possible substrings.
Now the scoring criteria is like: a player gains 1 point for each occurrence of the substring in the string s. We have to find winner of this game and his score.
So, if the input is like s = "BANANA", then the output will be Bimal, 12 because
|Word : BANANA|
|Total 9||Total 12|
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding
def solve(word): vowels = set('AEIOU') p1 = 0 p2 = 0 for i, c in enumerate(word): if c in vowels: p2 += len(word) - i else: p1 += len(word) - i if p1 > p2: return 'Bimal', p1 elif p2 > p1: return 'Amal', p2 else: return 'Draw' word = "BANANA" print(solve(word))