Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For Part C, you will be creating an interface for two people to play a simple ga

ID: 3590245 • Letter: F

Question

For Part C, you will be creating an interface for two people to play a simple game of “Pick-Up Sticks.” Here’s how the game is to be played.

The game begins with a number of sticks on a table—between 10 and 100.

Each player, in turn, picks up 1–3 sticks off the table.

The player to take the last stick loses.

Your job is to build a virtual version of the game using Python. The program is broken into a series of parts to help you understand how to put together a game with several different components. Each part builds on the previous one so you should complete them in order and only turn in the final part (the two-player version) as your solution.

Single-Player Game

Begin by asking the user for a number of sticks to be used in the game. Only accept numbers between 10 and 100—if the user supplies a number outside of this range you should prompt them to re-enter the number.

Next, continually announce to the user how many sticks are on the table and ask the user to enter a number of sticks to take away. Only accept choices of 1, 2, or 3 sticks—anything else should cause an error message to be displayed. Once a valid number of sticks has been entered, you should deduct that number from the total number of sticks in the game. When you reach 0 sticks left, the game is over.

Here is a sample running of the program.

Two-Player Game

As you can see, the single-player version of this game isn’t very fun. To make things more interesting we are now going to add an element of competition. For this part you will be implementing a two-player game where players take turns picking up sticks from the table. The same rules apply—each player can only take 1, 2, or 3 sticks per turn. The player who takes the last stick off of the table loses.

Here is a sample running of the game.

Here are some hints to get you started.

You may want to use a variable to keep track of the players and who’s turn it is.

You only want to switch turns when the player takes a valid number of sticks.

Don’t allow players to take more than the total number of sticks on the table. For example, if there are two sticks left the player should not be able to take three sticks.

The player who does not take the last stick is the winner.

Explanation / Answer

def current_player_turn(sticks, name):
if name == 1:
return player_one(sticks, name)
else:
return player_two(sticks, name)

def player_one(sticks,name):
print('Turn player 1')
print('There are {} sticks on the table'.format(sticks))
while True:
number = int(input("How many sticks do you take(1-3)? "))
if number >= 1 and number <= 3:
if sticks < number:
print('There are {} sticks only'.format(sticks))
else:
break
else:
print("Sorry, that's not a valid number.")
sticks -= number
return sticks_a_turn(sticks,name)

def player_two(sticks,name):
print('Turn player 2')
print('There are {} sticks on the table'.format(sticks))
while True:
number = int(input("How many sticks do you take(1-3)? "))
if number >= 1 and number <= 3:
if sticks < number:
print('There are {} sticks only'.format(sticks))
else:
break
else:
print("Sorry, that's not a valid number.")
sticks -= number
return sticks_a_turn(sticks,name)

def sticks_a_turn(sticks,name):
if sticks < 1:
print('There are no sticks left on the table. Game over.')  
print('Player {} takes the last stick and loses'.format(name))
return sticks
else:
return sticks

def main():
print("Welcome to the Game of Sticks!")
player_one_name = 1
player_two_name = 2
while True:
sticks = int(input("How many sticks to start with (10-100)? "))
if sticks>=10 and sticks<=100:
break
else:
print("Sorry, that's not a valid number.")
  
while sticks > 0:
name = player_one_name
sticks = current_player_turn(sticks, name)
if sticks==0:
break
name = player_two_name
sticks = current_player_turn(sticks, name)
if __name__ == '__main__':
main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote