We are tasked with finding which minion, Stuart or Kevin, won the minion game (The rules are explained in the link above).
My solution does the following:
- Initialize two variables
sandkto keep track of the scores for Stuart and Kevin, respectively. These variables represent the cumulative score for each player. - Create a list
vowelscontaining the vowels 'A', 'E', 'I', 'O', and 'U'. This will be used to check whether a letter is a vowel. - Iterate through the indices of the input string using a for loop (
for i in range(len(string))). - Inside the loop, check if the character at the current index (
string[i]) is a vowel. If it is, increment the scorekby the length of the remaining substring starting from the current index (k += len(string[i:])). This counts all substrings starting with a vowel. - If the character is not a vowel (i.e., a consonant), increment the score
sby the length of the remaining substring starting from the current index (s += len(string[i:])). This counts all substrings starting with a consonant. - After the loop, compare the scores of Stuart (
s) and Kevin (k). - If
sis greater thank, print 'Stuart' and the scores. - If
kis greater thans, print 'Kevin' and the scorek. - If both scores are equal, print 'Draw'.