so i have an assignment for a class to make a pick up sticks game. This is the actual assignment:
"The rules of pick up sticks are as follows: The user chooses the number of matchsticks (5 to 50) 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 chooses 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.) If you have written this program correctly, the computer should win every game."
My main question is how am i to make the program chose the "proper number of sticks"? and also if you see that I did something wrong or could do something better, let me know!
def count(sticks):
cnt=""
if sticks>1:
print("There are currently", sticks, "sticks on the pile.")
elif sticks==1:
print("There is currently 1 stick on the pile.")
while sticks>0:
cnt+="|"
sticks-=1
print("Current status of the pile:")
print("*",cnt,"*")
cnt=""
def computer(sticks):
print("I will pick up 1 stick")
sticks-=1
return sticks
def game(sticks):
while sticks>0:
if sticks>=5 and sticks<=50:
if sticks%4==1:
print("You can go first.")
count(sticks)
choice=int(input("How many sticks would you like to pick up? "))
if choice<=sticks:
sticks-=choice
count(sticks)
else:
print("Invalid choice. Please try again.")
choice=int(input("How many sticks would you like to pick up? "))
if choice<=sticks:
sticks-=choice
count(sticks)
print("I will pick up 1 stick")
choice-=1
count(sticks)
if sticks==1:
choice=int(input("How many sticks would you like to pick up? "))
if choice==1:
sticks-=choice
else:
print("Invalid choice. Please try again.")
choice=int(input("How many sticks would you like to pick up? "))
if choice==1:
sticks-=choice
else:
print("I will go first.")
count(sticks)
print("I will pick up 1 stick.")
sticks-=1
count(sticks)
choice=int(input("How many sticks would you like to pick up?"))
if choice<4 and choice>0:
sticks-=choice
count(sticks)
print("I will pick up 1 stick")
choice-=1
count(sticks)
if sticks==1:
choice=int(input("How many sticks would you like to pick up? "))
if choice==1:
sticks-=choice
print("I will pick 3 sticks")
else:
print("Invalid choice. Please try again.")
choice=int(input("How many sticks would you like to pick up? "))
if choice==1:
sticks-=choice
else:
print("That number is not between 5 and 50. Please try again")
sticks=int(input("How many sticks would you like there to be in the pile? Choose a number between 5 and 50."))
game(sticks)
return
sticks=int(input("How many sticks would you like there to be in the pile? Choose a number between 5 and 50."))
game(sticks)
print("You picked up the last stick. I won!")
Thank you for the help!