Question: Python Def Update(Token_counts, Row, Takes): The Update Method Takes Three Parameters Token Counts, Row, And Takes. While These Have The Same Name As The Parameters

Python Def Update(Token_counts, Row, Takes): The Update Method Takes Three Parameters Token Counts, Row, And Takes. While These Have The Same Name As The Parameters To The Is Valid Function, There Are Important Differences. 6 Like Before, Token Counts Is A List Of Token Counts For Each Row In A Nim Game (Similar To One That Create Token Counts Might Return).

python

def update(token_counts, row, takes):

The update method takes three parameters token counts, row, and takes. While these have the same name as the parameters to the is valid function, there are important differences. 6 Like before, token counts is a list of token counts for each row in a nim game (similar to one that create token counts might return). row is an int representing which row the user has requested to take tokens from this will be 0-indexed (not 1-indexed like the user input) and therefore will represent a list index directly. takes is an int representing how many tokens the user wishes to take. The function should return a newly created list that represents the board after the listed number of tokens have been taken from the listed row. Example: if you call update([5,3,4,1], 2, 3) it should return [5,3,1,1] (index 2 in the array has been reduced by 3, the rest are unchanged.) The input list should remain unchanged.

You can assume that row and takes are integers, that row is a valid index for the token counts list, and that takes is between 1 and 3, and not greater than token_counts [i]. This is to say, you can assume that these parameters indicate a valid move as previously defined.

Remember that the row is a 0-indexed integer in this problem, not a 1-indexed string like the last problem. You can use it directly like a list index.

The token counts list input to this function should be unmodified by this function (I.E. it should have the same value before and after this function runs)

The returned list should be a copy of the input list except for the index indicated by row which should have fewer tokens as indicated by the takes variable. Hints:

This functions requirements may not match your expectations make sure to read them carefully. For instance, the parameters here are formatted differently than the ones in the previous function.

Despite the name the function does not actually update a list. Remember its job is to create a new list, NOT change the list given to it.

This function is a bit hard to describe, and therefore it can be a bit hard to understand. Make sure you have a sense of what this is expected to do before you start coding. A great way to do that is to review the tester code provided with this assignment.

tester =

tokens = [3, 2, 1]

result = update(tokens, 2, 1)

print(tokens, result) # [3, 2, 1] [3, 2, 0]

tokens = [4, 3, 2, 1, 0]

result = update(tokens, 3, 1)

print(tokens, result) # [4, 3, 2, 1, 0] [4, 3, 2, 0, 0]

tokens = [9, 8, 7, 6, 5, 4, 3]

result = update(tokens, 6, 2)

print(tokens, result) # [9, 8, 7, 6, 5, 4, 3] [9, 8, 7, 6, 5, 4, 1]

tokens = [8, 7, 6, 5]

result = update(tokens, 0, 3)

print(tokens, result) # [8, 7, 6, 5] [5, 7, 6, 5]

tokens = [5, 4, 3, 2, 1]

result = update(tokens, 1, 1)

print(tokens, result) # [5, 4, 3, 2, 1] [5, 3, 3, 2, 1]

tokens = [4, 3, 2, 1]

result = update(tokens, 1, 2)

print(tokens, result) # [4, 3, 2, 1] [4, 1, 2, 1]

def draw_board(token_counts):

The draw board function takes one parameter, token counts is a list of token counts for each row in a nim game (similar to one that create token counts might return) You can assume that the token counts list contains only non-negative numbers. The draw board function has no return value, and should instead use print statements to produce an output directly to the terminal. 7 The output of the function is a depiction of the state of the game, for instance, if given the list [5,2,3,1] The following should be printed:

Game board.

====================

1 $$$$$

2 $$

3 $$$

4 $

====================

Formally: The first line should simply read Game board.

The second line should be empty

The third line should contain 20 equal-signs.

for a list length n, the next n lines should be the row number, followed by a single space, and then a number of dollar-signs $ as indicated by the token counts list. The final line should contain 20 equal-signs.

No line starts-with or ends-with any spaces.

Your output must match letter to letter including spaces, newlines, capitalization, symbols etc.

def is_over(token counts) :

The is over function takes one parameter, token counts which is a list of token counts for each row in a nim game (similar to one that create token counts might return). This function returns a boolean value to indicate if the game is over. If every value in the input list is 0 the game is over. If any value is not 0 the game is not over. (You can assume the list is not empty I.E. it has at least one thing in it.)

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!