如何使用用户输入和打印更新列表来减少列表中的值
How to reduce values in list using user input and printing updated list
所以我正在尝试构建一个 NIM 游戏。我坚持从列表中减少并打印出更新的列表:
#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)
当我在用户输入的更改后尝试打印电路板时,列表没有改变。我显然错过了一些东西。
感谢帮助
谢谢
reducer 没有修改板,它只是调用它的值,对它们执行操作,然后不对输出做任何事情。我认为你需要做
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)
那是说我不熟悉 NIM,所以我不确定您的目标是什么。
所以我正在尝试构建一个 NIM 游戏。我坚持从列表中减少并打印出更新的列表:
#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)
当我在用户输入的更改后尝试打印电路板时,列表没有改变。我显然错过了一些东西。 感谢帮助 谢谢
reducer 没有修改板,它只是调用它的值,对它们执行操作,然后不对输出做任何事情。我认为你需要做
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)
那是说我不熟悉 NIM,所以我不确定您的目标是什么。