[英]How to reduce values in list using user input and printing updated list
So I am trying to build a NIM game. 因此,我正在尝试构建NIM游戏。 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. 那就是说我对NIM不熟悉,所以我不确定您的目标是什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.