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")

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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()

Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education