Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this assignment you will be creating an interface for two humans to play a simple game of Pick Up Sticks. Here's how the game
For this assignment you will be creating an interface for two humans to play a simple game of "Pick Up Sticks". Here's how the game is played in the "real world":
- The game begins with a number of sticks on a table (between 10 and 100)
- Each player, in turn, takes between 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. Here are a few sample runnings of the program
Run #1
How many sticks are on the table? (enter a number between 10 and 100): 10 There are 10 sticks on the table. Turn: Player 1 How many sticks do you want to remove from the table? (1, 2 or 3):3 There are 7 sticks on the table. Turn: Player 2 How many sticks do you want to remove from the table? (1, 2 or 3):2 There are 5 sticks on the table. Turn: Player 1 How many sticks do you want to remove from the table? (1, 2 or 3):3 There are 2 sticks on the table. Turn: Player 2 How many sticks do you want to remove from the table? (1, 2 or 3):1 There are 1 sticks on the table. Turn: Player 1 How many sticks do you want to remove from the table? (1, 2 or 3):1 Player 1 loses!
Run #2
How many sticks are on the table? (enter a number between 10 and 100): 150 Invalid # of sticks, please try again. How many sticks are on the table? (enter a number between 10 and 100): -10 Invalid # of sticks, please try again. How many sticks are on the table? (enter a number between 10 and 100): 10 There are 10 sticks on the table. Turn: Player 1 How many sticks do you want to remove from the table? (1, 2 or 3):3 There are 7 sticks on the table. Turn: Player 2 How many sticks do you want to remove from the table? (1, 2 or 3):3 There are 4 sticks on the table. Turn: Player 1 How many sticks do you want to remove from the table? (1, 2 or 3):3 There are 1 sticks on the table. Turn: Player 2 How many sticks do you want to remove from the table? (1, 2 or 3):1 Player 2 loses!
Run #3
How many sticks are on the table? (enter a number between 10 and 100): 10 There are 10 sticks on the table. Turn: Player 1 How many sticks do you want to remove from the table? (1, 2 or 3):5 Invalid number of sticks, try again. There are 10 sticks on the table. Turn: Player 1 How many sticks do you want to remove from the table? (1, 2 or 3):-3 Invalid number of sticks, try again. There are 10 sticks on the table. Turn: Player 1 How many sticks do you want to remove from the table? (1, 2 or 3):3 There are 7 sticks on the table. Turn: Player 2 How many sticks do you want to remove from the table? (1, 2 or 3):3 There are 4 sticks on the table. Turn: Player 1 How many sticks do you want to remove from the table? (1, 2 or 3):1 There are 3 sticks on the table. Turn: Player 2 How many sticks do you want to remove from the table? (1, 2 or 3):1 There are 2 sticks on the table. Turn: Player 1 How many sticks do you want to remove from the table? (1, 2 or 3):1 There are 1 sticks on the table. Turn: Player 2 How many sticks do you want to remove from the table? (1, 2 or 3):1 Player 2 loses!
Run #4
How many sticks are on the table? (enter a number between 10 and 100): 10 There are 10 sticks on the table. Turn: Player 1 How many sticks do you want to remove from the table? (1, 2 or 3):3 There are 7 sticks on the table. Turn: Player 2 How many sticks do you want to remove from the table? (1, 2 or 3):3 There are 4 sticks on the table. Turn: Player 1 How many sticks do you want to remove from the table? (1, 2 or 3):3 There are 1 sticks on the table. Turn: Player 2 How many sticks do you want to remove from the table? (1, 2 or 3):3 You can't take that many sticks off of the table. Try again. There are 1 sticks on the table. Turn: Player 2 How many sticks do you want to remove from the table? (1, 2 or 3):100 Invalid number of sticks, try again. There are 1 sticks on the table. Turn: Player 2 How many sticks do you want to remove from the table? (1, 2 or 3):0 Invalid number of sticks, try again. There are 1 sticks on the table. Turn: Player 2 How many sticks do you want to remove from the table? (1, 2 or 3):1 Player 2 loses!
Here are some hints to get you started:
- You should begin by letting the user decide how many sticks they will start off with. You can assume that the user will input a number, but you need to make sure that the selection was between 10 and 100. Hint: use a while loop!
- You will need to keep track of turns in the game (i.e. Player 1's turn, Player 2's turn, etc). However, it might be easier to take care of this later in the game. When you begin writing your program you might want to design the game to only work with one player to begin with (i.e. it's always Player 1's turn) - you can add in the functionality for Player 2 later on once you've perfected the mechanics for Player 1.
- Each player can take between 1 and 3 sticks from the table. They cannot take more than 3 or less than 1. You cannot assume the user will give you a number between 1 and 3 so you will need to "validate" their data and only accept numbers between 1 and 3.
- You need to make sure the players don't take more sticks than are on the table (i.e. if there are 2 sticks left the user cannot take 3)
- When there are 0 sticks on the table the player who took the last stick is the loser. The game ends at this point
- The game starts off with Player 1's turn and will switch to Player 2's turn once Player 1 finishes their turn. You might want to think about creating a variable to help keep track of this information.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started