Question: Having issues when I'm running this python code on idle and can't figure out why. I'm thinking it has to do with the random numbers

Having issues when I'm running this python code on idle and can't figure out why. I'm thinking it has to do with the random numbers or the % int functions. def main(): import random # Generate a random integer between 10 and 100 to denote the initial size of the pile.  numOfMarbles = random.randint(10, 100) print("The size of the pile is:"), numOfMarbles # Generate a random integer between 0 and 1 to decide wheter the computer or the human takes the first turn.  turn = random.randint(0, 1) if turn == 0: print("Its the turn of a computer") else: print("Its your turn") # Generate a random integer between 0 and 1 to decide whether the computer plays smart or stupid.  stupidComputer = random.randint(0, 1) if stupidComputer == 0: print("Vs Smart computer") else: print("Vs Dumb computer") # In stupid mode the computer simply takes a random legal value (between 1 and n/2)  # from the pile whenever it has a turn.  while numOfMarbles != 1: # Till you're left with only one marble.  if turn == 0: # Computer turn  if stupidComputer == 1: # If the computer is playing in stupid mode.  temp = random.randint(1, numOfMarbles / 2) # Select a random number between 1, and n/2.  else: # Select the marbles smartly.  if numOfMarbles - 3 > 0 and numOfMarbles - 3 < int(numOfMarbles / 2): temp = numOfMarbles - 3 elif numOfMarbles - 7 > 0 and numOfMarbles - 7 < int(numOfMarbles / 2): temp = numOfMarbles - 7 elif numOfMarbles - 15 > 0 and numOfMarbles - 15 < int(numOfMarbles / 2): temp = numOfMarbles - 15 elif numOfMarbles - 31 > 0 and numOfMarbles - 31 < int(numOfMarbles / 2): temp = numOfMarbles - 31 else: temp = numOfMarbles - 63 print("The computer picked: %d marbles." % temp) # Print the marbles picked by computer.  numOfMarbles -= temp # Subtract the marbles picked by computer.  else: marblesToPick = int(input("Its your turn. Pick the marbles in the range 1 - %d: ")) % int(numOfMarbles / 2) # Read the marbles to be picked.  while marblesToPick < 1 or marblesToPick > int(numOfMarbles / 2): # If read invalid value, try repeatedly.  marblesToPick = input("You picked the wrong count. Pick the marbles in the range 1 - %d: ") % int(numOfMarbles / 2) numOfMarbles -= marblesToPick # Subtract the marbles picked by you.  turn = (turn + 1) % 2 # Change the turn.  print("the pile is of size %d.") % numOfMarbles if turn == 0: # Declare the result.  print("You won.") else: print("The computer won") main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!