Skip to content

Commit 4be13bf

Browse files
committed
The minion game , HackerRank
1 parent 424cdbb commit 4be13bf

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#Kevin and Stuart want to play the 'The Minion Game'.
2+
3+
#Game Rules
4+
5+
#Both players are given the same string S .
6+
#Both players have to make substrings using the letters of the string S.
7+
#Stuart has to make words starting with consonants.
8+
#Kevin has to make words starting with vowels.
9+
#The game ends when both players have made all possible substrings.
10+
11+
#Scoring
12+
#A player gets +1 point for each occurrence of the substring in the string S.
13+
14+
#Function to find the winner
15+
def the_minion_game(s):
16+
17+
vowels = 'AEIOU'
18+
kevin = 0
19+
stuart = 0
20+
for i in range(len(s)):
21+
if s[i] in vowels:
22+
kevin += (len(s)-i)
23+
else:
24+
stuart += (len(s)-i)
25+
26+
if kevin > stuart:
27+
print ("Kevin won the game with score:", kevin)
28+
elif kevin < stuart:
29+
print ("Stuart won the game with score:", stuart)
30+
else:
31+
print ("Draw")
32+
33+
34+
s = input("Enter the String: ")
35+
the_minion_game(s)

0 commit comments

Comments
 (0)