Question: Hello, i need to modify this given Python code above in repl. to satisfy these new requirement instructions below. The new code must pick a

 Hello, i need to modify this given Python code above in

Hello, i need to modify this given Python code above in repl. to satisfy these new requirement instructions below.

repl. to satisfy these new requirement instructions below. The new code must

The new code must pick a random number between 20 and 30 instead of 20, Pick a random player, either 1 or 2 that will be the winner. And apply the winning strategy to which ever player was chosen at random. The computer must also be the one to input the numbers and play the roles of player 1 or 2, rather than a user inputting desired numbers like in the first code.

For the given code, the winning strategy if player one goes first and the winner was player 2,

player 2 would pick 1 coin if player 1 picked 3 coins,

or pick 2 coins if player 1 picked 2 coins,

or picked 3 coins if player 1 picked 1 coin,

resulting in player 2 always winning if player 1 went first, and if player 2 followed the strategy

1 turn = 0 remaining coins = 22 2 3 4 print("take turns removing 1, 2, or 3 coins") print("You win if you take the last coin.") 5 6 7 8 9 while remaining coins > : print(" There are", remaining coins, "coins remaining.") if turn%2 == : taken_coins = int(input("Player 1: How many coins do you take?")) else: taken_coins int(input("Player 2: How many coins do you take?")) 10 11 12 13 14 15 16 17 18 19 20 while taken_coins 3 or taken_coins > remaining_coins: print("That's not a legal move. Try again.") print(" There are", remaining_coins, "coins remaining.") if turn%2 == 0: taken_coins = int(input("Player 1: How many coins do you take?")) else: taken_coins = int(input("Player 2: How many coins do you take?")) 21 22 23 24 25 26 27 28 29 30 31 32 if remaining_coins - taken_coins 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 turn += 1 | Task 2: modify the program 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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!