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
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.