Question: Write a method add_checker(self, checker, col) that accepts two inputs: checker, a one-character string that specifies the checker to add to the board (either 'X'

Write a method add_checker(self, checker, col) that accepts two inputs:

checker, a one-character string that specifies the checker to add to the board (either 'X' or 'O').

col, an integer that specifies the index of the column to which the checkershould be added and that adds checker to the appropriate row in column col of the board.

Note that we begin with assert statements that validate the inputs for the parameters checker and col. If the condition given to assert isnottruee.g., if the input provided for checker is something other than the string 'X' or the string 'O'then assert will cause your code to crash with an AssertionError. Using assert in this way can help you to find and debug situations in which you accidentally pass in incorrect values for the parameter of a function.

Other notes:

Remember that the checker slides down from the top of the board. Therefore, your code will have to find the appropriate row number available in column col, and place the checker in that row.

We reviewed a buggy version of this method in lecture that you may find it helpful to review.

This method doesnotneed to check that col is a legal column number, or that there is enough space in the column col.

the first code is the code I have and the second code is what was given to us

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 Programming Questions!