PYTHON IDLE print("Choose the number of matchsticks (between 5 and 40). The computer will decide who goes first. Remove one, two or three matchsticks from the pile. The contestant who removes the last matchstick loses.", "Rules of the Game")
Create a program called “fifteenth.py”. The object of this assignment is to write a program that allows the user to challenge the computer to a game of Pick-Up Sticks. Here is how the game is played. The user chooses the number of matchsticks (from 5 to 40) to place in a pile. Then, the computer chooses who will go first. At each turn, the contestant can remove one, two or three matchsticks from the pile. The contestant who removes the last matchstick loses.The computer should make the user always select from a pile where the number of matchsticks has a remainder of 1 when divided by 4. For instance, if the user initially chooses a number of matchsticks that has a remainder of 1 when divided by 4, then the computer should have the user go first. Otherwise, the computer should go first and remove the proper number of matchsticks.
[Note: The remainder when n is divided by 4 is (n % 4).] After writing the program, play a few games with the computer and observe
PYTHON IDLE
print("Choose the number of matchsticks (between 5 and 40). The computer will decide who goes first. Remove one, two or three matchsticks from the pile. The contestant who removes the last matchstick loses.", "Rules of the Game")
def PlayAgain():
answer = input("Would you like to play a game? Y/N ")
if answer == "Y" or answer == "y":
newGame()
else:
print("Too bad. See ya.")
exit()
def newGame():
GetNumber()
OutputSticks()
WhoGoesFirst()
def GetNumber():
global numberOfSticks
numberOfSticks = int(input("Enter a number between 5 and 40 "))
if(numberOfSticks < 5) or (numberOfSticks > 40):
print("Invalid Input!")
GetNumber()
def OutputSticks():
global numberOfSticks
sticks = ""
for i in range(numberOfSticks):
sticks += "|"
print(sticks)
def WhoGoesFirst():
global numberOfSticks
if (numberOfSticks % 4) == 1:
print("Player Goes First")
PlayersTurn()
else:
print("Computer Goes First")
ComputersTurn()
def ComputersTurn():
global numberOfSticks
#Insert Code Here
print("This program needs some work")
def PlayersTurn():
global numberOfSticks
#Insert Code Here
print("This program needs some work")
newGame()
Step by step
Solved in 3 steps with 2 images