Starting from:
$14.99

$8.99

Python 3 Solution

We are going to play a game. You start with a bunch of circles (we will start with 16 circles ) and two players. Each player can remove 1, 2, or 3 circles from the of 16. Each player is required to take some number of circles from the pile during each turn.

The players take turns removing circles, and the player who takes the last bean from the pile is the loser.

Each player is to be represented by a function, so we will have two functions. Each function takes a single argument, representing the present number of circles, and returns the number of circles remaining after the player function takes its turn. During the operation of the player function, the function reports (prints) how many circles were removed.

Note that the function decides how many circles to remove. It takes no input from the user.

You also need a main program. The main program initializes the circles to 16 and then alternately calls the first player function and the second player function until one of them gets the last circle. The main then reports who the loser is and exits.

( this is how the code should look when it is run)

Welcome to a game of circles!

Player 1 press enter to play your turn

OOOOOOOOOOOOOOOO

player 1 removed 3 circles

OOOOOOOOOOOOO

Player 2 press enter to play your turn

OOOOOOOOOOOOO

player 2 removed 2 circles

OOOOOOOOOOO

( the player who removes the last 1 circle loses)

 

More products