Modify the following code so that:
Make the pool start with a random number ([20, 30] inclusive) of coins.
Based on the number of the randomly generated coins at the beginning,
let the computer determine whether Player 1 or Player 2 will be the
winner based on the winning strategy (by printing out the winner).
After deciding the supposed winner and loser, let the computer play
out both of the roles. For the winner, the computer should be applying
the winning strategy; for the loser, the computer should generate a
random amount of coins while following all the rules of the game
Rules of the game:
a) The game starts with 22 coins in a common pool
b) The goal of the game is to take the last coin
c) Two players take turns removing 1, 2, or 3 coins from the pool
d) A player can NOT take more coins than remaining coins in the pool
e) After each turn, the judge announces how many coins remain in the
pool
f) When the last coin is taken, the judge announces the winner
turn=0 #turn=1 remaining coins-24 print(Take turns removing 1, 2, or 3 coins. ) print(You win if you take the last coin.)

Answers

Answer 1

Answer:

Explanation:

The following code makes all the necessary changes so that the game runs as requested in the question. The only change that was not made was making the number of coins random since that contradicts the first rule of the game that states that the game starts with 22 coins.

turn = 0

remaining_coins = 22

print("Take turns removing 1, 2, or 3 coins. ")

print("You win if you take the last coin.")

while remaining_coins > 0:

   print("\nThere are", remaining_coins, "coins remaining.")

   if turn % 2 == 0:

       # Player1

       taken_coins = int(input("Player 1: How many coins do you take?"))

       turn += 1

   else:

       # Player2

       taken_coins = int(input("Player 2: How many coins do you take?"))

       turn += 1

   if taken_coins < 1 or taken_coins > 3 or taken_coins > remaining_coins:

       print("That's not a legal move. Try again. ")

       print("\nThere are", remaining_coins, "coins remaining.")

       if turn % 2 == 0:

           # Player1

           taken_coins = int(input("Player 1: How many coins do you take? "))

           turn += 1

       else:

           # Player2

           taken_coins = int(input("Player 2: How many coins do you take? "))

           turn += 1

       remaining_coins -= taken_coins

   else:

       remaining_coins -= taken_coins

   if remaining_coins - taken_coins == 0:

       print("No more coins left!")

       if turn % 2 == 0:

           print("Player 1 wins!")

           print("Player 2 loses !")

       else:

           print("Player 2 wins!")

           print("Player 1 loses!")

           remaining_coins = remaining_coins - taken_coins

   else:

       continue


Related Questions

Other Questions
Victor buys four chairs to place around his dining room table. He pays a total of $88. What is the unitprice? 1. Which statement about leaders and managers is most likely false?a)Managers are concerned with the efficiency of results, whereas leaders areprimarily concern with results.b)Leaders focus on risk taking whereas managers focus on planningc)Leaders accept the status quo, managers challenge it.d)Leaders develop but managers maintain. Clarissa has a budget of $1,200 a month to spend for rent and food. She has already spent $928 this month. Which inequality represents the amount she can still spend this month and remain within her budget?x greater-than 272x less-than-or-equal-to 272x less-than 272x greater-than-or-equal-to 272 Someone pls help this is for my presentation about Tornados..What is the temperature like before, during, and after your extreme type of weather?I literally dont know what to put so someone plss help it would rlly mean the world to me Fill in the blank with the correct word.Figure it out amongstO yoursoyourselvesStmO yourselfO themselves which is an equation of a line through (7,1) and perpendicular to y=-x+3 two printers working together can print a 250 page book in 30 minutes. printer a takes twice as long as printer b to print the same book. how long would it take each printer working alone to print the book. let the variable x = how many minutes it takes to print the book. Using units of books/minutes, write an equation involving rates using rational functions, solve for x, and interpret the results in context. 10 points!! choose que or como:1. Pedro tiene ms libros (que/como) su amigo.2. Sara toca la guitarra mejor (que/como) su hermano.3. Ricardo es tan trabajador (que/como) su hermano. What does citizenship means in social studies HELP IM STUCK ON TWO MATH QUESTION HELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELPHELP recommend two ways in which women and children can be protected from discrimination and violence help, please? What science law explains why there should always be the same type of elements on the reactant side as there are on the product side? What does this law state? (HINT: Answer both of these questions. A: The Law of _________________ states that _____________.) Plz answer question! Due in 7 minutes!!! Will make BRAINLIEST for first correct answer!!! Show your work: 1/2x = 10 A coordinate grid has a scale of 1unit = 100 miles. How far apart, inmiles, are points (-3, 2) and (-3,12)? A triangle with an area of 37 units? is dilated by a scale factor of . Find the area ofthe triangle after dilation. Round your answer to the nearest lenth, if necessary. Quirch Inc. manufactures machine parts for aircraft engines. The CEO, Chucky Valters, was considering an offer from a subcontractor that would provide 2,400 units of product PQ107 for Valters for a price of $150,000. If Quirch does not purchase these parts from the subcontractor it must produce them in-house with the following unit costs: Cost per Unit Direct materials $31 Direct labor 19 Variable overhead 8 In addition to the above costs, if Quirch produces part PQ107, it would have a retooling and design cost of $9,800. The relevant costs of producing 2,400 units of product PQ107 internally are:______.a. $149,000. b. $129.800. c. $150,000. d. $164,200. e. $148.300. Please help, and I'll give brainliest! The following dot plot represents a random sample of elementary students and the number of children that live in their home.Which of the following numbers is an outlier?16342 What is the other product for this reaction ? H3PO4 + Ca(OH)2 > H20 + _________ What is the function of the liver and pancreas?to aid digestion in the stomachto filter the bloodto aid digestion in the small intestine