Project - The Minion Game #13
Replies: 9 comments
-
def consonant(str):
index = 0
total = str.__len__()
suma = 0
for i in str:
if i not in "AEIOU":
suma += total - index
index+=1
return suma
def vowels(str):
index = 0
total = str.__len__()
suma = 0
for i in str:
if i in "AEIOU":
suma += total - index
index+=1
return suma
inp = input("Enter the word")
stuart = consonant(inp)
kevin = vowels(inp)
if stuart == kevin:
print("DRAW")
elif stuart > kevin:
print(f"Stuart wins with score: {stuart}")
else:
print(f"Kevin wins with score: {kevin}") |
Beta Was this translation helpful? Give feedback.
-
def minion_game(string):
vowels = "AEIOU"
Stuart_score, Kevin_Score = 0, 0
length = len(string)
for start_idx in range(length):
score = length - start_idx
if string[start_idx] in vowels:
Kevin_Score += score
else:
Stuart_score += score
if Kevin_Score > Stuart_score:
print("The winner is Kevin: ", Kevin_Score)
elif Kevin_Score < Stuart_score:
print("The winner is Stuart: ", Stuart_score)
else:
print("It's a DRAW.")
if __name__ == '__main__':
s = input("Enter the word for the game: ")
minion_game(s) |
Beta Was this translation helpful? Give feedback.
-
def minion_game(string):
string = string.upper()
kevin = vowel(string)
stuart = consonant(string)
if kevin == stuart:
print('draw')
elif kevin < stuart:
print("Stuart win")
else:
print("Kevin win")
def vowel(string):
index = 0
total = len(string)
sum = 0
for i in string:
if i in "AEIOU":
sum = sum + total -index
index += 1
return sum
def consonant(string):
index = 0
total = len(string)
sum = 0
for i in string:
if i not in "AEIOU":
sum = sum + total - index
index += 1
return sum
if __name__ == '__main__':
s = input("Enter a word: ")
minion_game(s) |
Beta Was this translation helpful? Give feedback.
-
def minion_game(string):
player1 = 0;
player2 = 0;
str_len = len(string)
for i in range(str_len):
if s[i] in "AEIOU":
player1 += (str_len)-i
else :
player2 += (str_len)-i
if player1 > player2:
print("Kevin", player1)
elif player1 < player2:
print("Stuart",player2)
elif player1 == player2:
print("Draw")
else :
print("Draw")
if __name__ == '__main__':
s = input()
minion_game(s) |
Beta Was this translation helpful? Give feedback.
-
def game(string):
player1 = 0
player2 = 0
str = len(string)
for i in range(str):
if s[i] in "AEIOU":
player1 = player1+ (str)-i
else :
player2 = player2+ (str)-i
if player1 > player2:
print("Kevin", player1)
elif player1 < player2:
print("Stuart",player2)
elif player1 == player2:
print("Draw")
else :
print("Draw")
if __name__ == '__main__':
s = input()
game(s) |
Beta Was this translation helpful? Give feedback.
-
def minion_game(string):
# your code goes here
stuartPoints = 0
kevinPoints = 0
vowels = 'aeiou'
for i in range(len(string)):
if string[i] in vowels:
kevinPoints += len(string[i:])
else:
stuartPoints += len(string[i:])
if kevinPoints != stuartPoints:
print("Kevin won with " + str(kevinPoints) if kevinPoints > stuartPoints else "Stuart Won with " + str(stuartPoints))
else:
print("Draw")
if __name__ == '__main__':
s = input()
minion_game(s) |
Beta Was this translation helpful? Give feedback.
-
def minion_game(string):
vowels = 'AEIOU'
kevin = stuart = 0
for i in range(len(s)):
if s[i] in vowels:
kevin += len(s) - i
else:
stuart += len(s) - i
x = ("Kevin",kevin) if kevin>stuart else (("Stuart",stuart) if kevin<stuart else "Draw")
print(x)
if __name__ == '__main__':
s = input().upper()
print(s)
minion_game(s) |
Beta Was this translation helpful? Give feedback.
-
Minion GameUsing regrex # substring game
import re
def main():
stuartScore = 0
kevinScore = 0
word = input("Enter a word (UPPERCASE): ")
# generate all substrings using list comprehension
subString = [word[i:j] for i in range(len(word)) for j in range(i+1,len(word)+1)]
# join the list of substrings to a string to use regex
# join from set to remove duplicates
joinSubs = ' '.join(set(subString))
# separate subStrings for Stuart (starting with consonant) and Kevin (starting with vowel)
kevinSub = list(set(re.findall("[AEIOU]\w*",joinSubs)))
stuartSub = list(set(re.findall("[^AEIOU ]\w*",joinSubs)))
# problem with the spaces in the string, list(set()) to delete duplicates
# print(re.findall("[AEIOU]\w+",joinSubs))
# print(joinSubs)
# print(kevinSub,stuartSub)
# Counting points
for sub in kevinSub:
count = word.count(sub)
kevinScore += count
for sub in stuartSub:
count = word.count(sub)
stuartScore += count
# winner
if kevinScore > stuartScore:
print(f"Kevin wins with {kevinScore} points!")
elif kevinScore == stuartScore:
print("Draw")
print(f"Kevin got {kevinScore} points!")
print(f"Stuart got {stuartScore} points!")
else:
print(f"Stuart wins with {stuartScore} points!")
# run main
if __name__ == "__main__":
main() |
Beta Was this translation helpful? Give feedback.
-
MANUAL GAME, NEED TO BE PLAYED BY THE USER, FINISH UNTIL YOU USE ALL THE POSSIBLES SUBSTRINGS allconsonantodds = []
allconsonantoddsused = []
allvowelodds = []
allvoweloddsused = []
def consonantsodds(word):
vowels = ("a", "e", "i", "o", "u")
consonant = [i for i in word if i not in vowels]
indexconsonant = []
for i in range(len(consonant)):
for x in range(len(word)):
if consonant[i] == word[x]:
indexconsonant.append(x)
indexconsonant = list(set(indexconsonant))
for i in range(len(indexconsonant)):
for x in range(indexconsonant[i] + 1,len(word)+1):
consonant.append(word[indexconsonant[i]:x])
global allconsonantodds
allconsonantodds = list(set(consonant))
def vowelodds(word):
vowels = ("a", "e", "i", "o", "u")
vowelsinword = [i for i in word if i in vowels]
indexvowel = []
for i in range(len(vowelsinword)):
for x in range(len(word)):
if vowelsinword[i] == word[x]:
indexvowel.append(x)
indexvowel = list(set(indexvowel))
for i in range(len(indexvowel)):
for x in range(indexvowel[i] + 1,len(word)+1):
vowelsinword.append(word[indexvowel[i]:x])
global allvowelodds
allvowelodds = list(set(vowelsinword))
def points(substring, word):
i = 0
point = 0
while i < len(word) - len(substring) + 1:
if substring == word[i:i+len(substring)]:
point = point + 1
i = i + 1
return point
def minion_game(string):
global allconsonantodds
global allvowelodds
global allconsonantoddsused
global allvoweloddsused
vowels = ("a", "e", "i", "o", "u")
kevinpoint = 0
stuartpoint = 0
while not len(allconsonantodds) == 0 or not len(allvowelodds) == 0:
if not len(allconsonantodds) == 0:
kevin = input("Turn of kevin (write a word):")
if kevin[0] in vowels:
print("Your word need to start with consonant!!!")
else:
if not kevin in allconsonantoddsused:
allconsonantodds.remove(kevin)
allconsonantoddsused.append(kevin)
kevinpoint = kevinpoint + int(points(kevin, string))
if len(allconsonantodds) == 0:
print("You put all the possible words, you finish your turns. wait for the other player")
else:
print("You use that word before: tried with other!")
if not len(allvowelodds) == 0:
stuart = input("Turn of stuart (write a word):")
if not stuart[0] in vowels:
print("Your word need to start with vowel!!!")
else:
if not stuart in allvoweloddsused:
allvowelodds.remove(stuart)
allvoweloddsused.append(stuart)
stuartpoint = stuartpoint + int(points(stuart, string))
if len(allvowelodds) == 0:
print("You put all the possible words, you finish your turns. wait for the other player")
else:
print("You use that word before: tried with other!")
print("Game over \n The punctuation is kevin: ", kevinpoint, "\n and stuart: ", stuartpoint)
if stuartpoint == kevinpoint:
print("DRAW!!")
elif stuartpoint > kevinpoint:
print("Stuart Wins!!")
else:
print("Kevin Wins!!")
if __name__ == '__main__':
s = input("Word of the game: ")
consonantsodds(s)
vowelodds(s)
minion_game(s) GAME AUTOMATIC ONLY PUT THE WORD AND THE WINNER GOING TO BE CHOOSE allconsonantodds = []
allvowelodds = []
def consonantsodds(word):
vowels = ("a", "e", "i", "o", "u")
consonant = [i for i in word if i not in vowels]
indexconsonant = []
for i in range(len(consonant)):
for x in range(len(word)):
if consonant[i] == word[x]:
indexconsonant.append(x)
indexconsonant = list(set(indexconsonant))
for i in range(len(indexconsonant)):
for x in range(indexconsonant[i] + 1,len(word)+1):
consonant.append(word[indexconsonant[i]:x])
global allconsonantodds
allconsonantodds = list(set(consonant))
def vowelodds(word):
vowels = ("a", "e", "i", "o", "u")
vowelsinword = [i for i in word if i in vowels]
indexvowel = []
for i in range(len(vowelsinword)):
for x in range(len(word)):
if vowelsinword[i] == word[x]:
indexvowel.append(x)
indexvowel = list(set(indexvowel))
for i in range(len(indexvowel)):
for x in range(indexvowel[i] + 1,len(word)+1):
vowelsinword.append(word[indexvowel[i]:x])
global allvowelodds
allvowelodds = list(set(vowelsinword))
def points(substring, word):
i = 0
point = 0
while i < len(word) - len(substring) + 1:
if substring == word[i:i+len(substring)]:
point = point + 1
i = i + 1
return point
def minion_game(string):
global allconsonantodds
global allvowelodds
vowels = ("a", "e", "i", "o", "u")
kevinpoint = 0
stuartpoint = 0
for i in range(len(allconsonantodds)):
kevin = allconsonantodds[i]
kevinpoint = kevinpoint + int(points(kevin, string))
for i in range(len(allvowelodds)):
stuart = allvowelodds[i]
stuartpoint = stuartpoint + int(points(stuart, string))
if stuartpoint == kevinpoint:
print("DRAW!!")
elif stuartpoint > kevinpoint:
print("Stuart Wins!! \n", stuartpoint)
else:
print("Kevin Wins!! \n", kevinpoint)
if __name__ == '__main__':
s = input("Word of the game: ")
consonantsodds(s)
vowelodds(s)
minion_game(s) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The Minion Game
Problem
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 wovels.
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 wovel beginning word =
ANA
Here,
ANA
occurs twice inBANANA
. Hence, Kevin will get 2 points.For better understanding, see the image below :
Input Format
A single line of input containing the full name,
S
.Note : The string
S
will contain only uppercase letters:[A - Z]
.Constraints
0 <
len(S)
< 106Output Format
Print one line : the name of the winner and their score separated by a space.
If the game is a draw, print
Draw
Sample Input
Sample Output
Note: Vowels are only defined as
AEIOU
. In this problem,Y
is not considered a vowel.Given Code
Beta Was this translation helpful? Give feedback.
All reactions