Kevin and Stuart want to play the ‘The Minion Game’.

Game Rules
Both players are given the same string, S .
Both players have to make substrings using the letters of the string S .
Stuart has to make words starting with consonants.
Kevin has to make words starting with vowels.
The game ends when both players have made all possible substrings.
Scoring
A player gets +1 point for each occurrence of the substring in the string S.
For Example:
String S = BANANA
Kevin’s vowel beginning word = ANA
Here, ANA occurs twice in BANANA. Hence, Kevin will get 2 Points.
Go to problem statement

Explanation Video:

Youtube Channel partner: CodingCart
Mentor: Satyendra Jaiswal
Langauge: Python

Source Code: For minion_game function


def minion_game(s):
    s1=0
    s2=0
    vow='AEIOU'
    for i in range(len(s)):
        if s[i] not in vow:
            s1=s1+(len(s)-i)
        else:
            s2=s2+(len(s)-i)   
    if s1>s2:
        print("Stuart",s1)
    elif s2>s1:
        print("Kevin",s2)
    else:
        print("Draw")          
coming soon…
coming soon…

Full Source Code:


def minion_game(s):
    s1=0
    s2=0
    vow='AEIOU'
    for i in range(len(s)):
        if s[i] not in vow:
            s1=s1+(len(s)-i)
        else:
            s2=s2+(len(s)-i)   
    if s1>s2:
        print("Stuart",s1)
    elif s2>s1:
        print("Kevin",s2)
    else:
        print("Draw")    
if __name__ == '__main__':
    s = input()
    minion_game(s)

coming soon…
coming soon…

Like this article? Follow us on Facebook and LinkedIn. You can also subscribe to our Youtube Channel.

This post is in partner with CodingCart.