過去兩天我一直在嘗試解決此錯誤,但我無法解決。我必須將值(這是一個列表)傳遞給函數,但它說:Typerror :list indices must be integers or slices and not str.這是我的代碼:def input_execute(board, position, mark): board[position] = markposition = input('enter the position')input_execute(board_items, position, 'x')輸出:enter the position:5如果我輸入它顯示的位置:Typerror :list indices must be integers or slices and not str.
1 回答

慕蓋茨4494581
TA貢獻1850條經驗 獲得超11個贊
下面的行返回字符串
position=input('enter the position')
現在將此行更改為
position=int(input('enter the position : '))
添加回答
舉報
0/150
提交
取消