0

So I am trying to build a NIM game. I got stuck with the reducing from the list and printing out an updated list instead:

#reduces from board-list
def reducer(choice_1, choice_2,board):
    if choice_1 == 'a':
        board[0] - int(choice_2) 
    if choice_1 == 'b':
         board[1] - int(choice_2) 
    if choice_1 == 'c':
        board[2] - int(choice_2)


def lets_play():
    import random
    board = [5,4,3]
    print ('a)   |')
    print ('b)  |||')
    print ('c) |||||')
    chosen_move = input('type in letter of choice:   ')
    chosen_move2 = input ('choose amount you wish to reduce:  ')
    reducer (chosen_move,chosen_move2,board)
    print (board)

When I try printing the board after the changes from the user input, the list does not change. I am obviously missing out on something. Appreciate the help Thanks

Grzegorz Adam Hankiewicz
  • 7,349
  • 1
  • 36
  • 78
  • 1
    `board[0] - int(choice_2) ` is a expression that changes nothing. Perhaps you meant `board[0] -= int(choice_2) `, so you assign back to the value in the list. – Paul Rooney Aug 01 '18 at 00:55

1 Answers1

0

reducer is not modifying board, it's just calling its values, performing an operation with them, and then doing nothing with the output. I think you need to do

def reducer(choice_1, choice_2,board):
    if choice_1 == 'a':
        board[0] -= int(choice_2) 
    if choice_1 == 'b':
         board[1] -= int(choice_2) 
    if choice_1 == 'c':
        board[2] -= int(choice_2)

That said I'm not familiar with NIM so I'm not sure what you're aiming for.

kevinkayaks
  • 2,636
  • 1
  • 14
  • 30