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

Trying to answer this question: My attept: I can\'t get the game to really work.

ID: 3772254 • Letter: T

Question

Trying to answer this question:

My attept:

I can't get the game to really work. What am I missing here?

code text:

def smart_ai(sticks):
"""make computer always win"""
while True:
print("Sticks left: " , sticks)
if sticks == 1:
print("You took the last stick, you lose")
break
if sticks%4==1:
sticks_taken = int(input("Take sticks(1-3):"))
if sticks_taken >= 4 or sticks_taken <= 0:
print("Wrong choice")
sticks-=sticks_taken
continue
if sticks%4==2:
print("Computer took: 1 stick ")
sticks -= 1
if sticks%4==3:
print("Computer took: 2 sticks ")
sticks-=2
  
sticks = int(input("How many sticks do you want to start with?/nChoose a number between 5 and 50,"))

print("There are",sticks,"sticks, you can take 1 to 3 sticks at a time.")
print("Last person to be left with one stick loses")

smart_ai(sticks)

2. Five, Six, Pick up Sticks. Write a program that allows the user to challenge the computer to a game of Pick-up-Sticks. Here is how to play the game. The user chooses the number of matchsticks (from 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 removes the last matchstick loses. See Fig. below. How many matchsticks would you like to pick up? And outer loop need be used, so that the user can continue play the game again and again. Hooray Five, Six, Pick up Sticks Give the Rules of the Game Begin a New Game I select 2 matchsticks. Iwin. How many matchsticks would you like to pick up? Current status of the pile: III One wo Three OK 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 Mod 4).] After writing the program, play a few games with the computer and observe that the computer always wins.

Explanation / Answer

program :
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!")