python3 includes three more doctest please Q5: Matches in the box For this probl
ID: 3713040 • Letter: P
Question
python3
includes three more doctest please
Q5: Matches in the box For this problem you need to use Mutual Recursion. If you are not sure how to use it, please refer to section 1.7.2 of our textbook. This games a two-player game. There are m matches in a box. The players take turns and can remove either one or two matches. The player who takes the last match wins. Your two friends decided to stick to a certain strategy: 1) Barack always removes a single match 2) Donald removes one match if an odd number of matches is in the box, and two matches otherwise Assume that there are m matches and Barack goes first, who wins the game? Output: You are expected to return one of the following strings, verbatim: "Donald wins the game" · "Barack wins the game. def barack(m): # YOUR CODE GOES HERE # def donald(m): # YOUR CODE GOES HERE # barack(3) Donald wins the gameExplanation / Answer
#python3 code
def barack(m):
if(m==0):
return "Donald wins the game"
else:
return donald(m-1)
def donald(m):
if(m==0):
return "Barack wins the game"
else:
if(m%2==0):
return barack(m-2)
else:
return barack(m-1)
if __name__=="__main__":
print(barack(3))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.