We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
STRAT_CON='c'STRAT_VOW='v'VALID_VOWELS='AEIOU'.split()classPlayer():def__init__(self,name,strategy):self.name=nameself.strategy=strategyself.score=0defis_vowel(self,ch:chr):returnany([ch==xforxinVALID_VOWELS])deffind_guesses(self,string:str,cmp_fn:lambdax:bool):foriinrange(len(string)):ifcmp_fn(string[i]):self.score+=len(string)-idefguess(self,string:str):ifself.strategy==STRAT_CON:self.find_guesses(string,lambdach:notself.is_vowel(ch))else:self.find_guesses(string,lambdach:self.is_vowel(ch))defminion_game(string):player_a=Player('Stuart',STRAT_CON)player_b=Player('Kevin',STRAT_VOW)player_a.guess(string)player_b.guess(string)# print the winner and scorewinner=player_aifplayer_b.score>player_a.score:winner=player_bifplayer_a.score==player_b.score:print('Draw')else:print('{}{}'.format(winner.name,winner.score))if__name__=='__main__':s=input()minion_game(s)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Minion Game
You are viewing a single comment's thread. Return to all comments →