运行以下代码时,我收到以下错误 - “list”对象不可调用 [英] While running the below code I am getting the following error - "list' object is not callable

查看:87
本文介绍了运行以下代码时,我收到以下错误 - “list”对象不可调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

test_board = ['1','2','3','4','5','6','7','8','9']

display_board(test_board)



def display_board(board):

print(| |)

print(+ board [6] +'|'+ board [7] +'|'+ board [8] +)

print('------------')

print(||)

print(+ board [ 3] +'|'+ board [4] +'|'+ board [5] +)

print('------- -----')

打印(| |)

print(+ board [0] +'|'+ board [ 1] +'|'+板[2] +)

结束



我有什么试过:



我试图将列表作为参数传递给函数display_board。

test_board = ['1','2','3','4','5','6','7','8','9']
display_board(test_board)

def display_board(board):
print(" | | ")
print(" "+board[6]+" "'|'" "+board[7]+" "'|'" "+board[8]+" ")
print('------------')
print(" | | ")
print(" "+board[3]+" "'|'" "+board[4]+" "'|'" "+board[5]+" ")
print('------------')
print(" | | ")
print(" "+board[0]+" "'|'" "+board[1]+" "'|'" "+board[2]+" ")
end

What I have tried:

I am trying to pass a list as an argument to a function display_board.

推荐答案

我刚试过你的代码,经过一点修改就可以了。删除文件底部的'end'语句。在调用它之前,您还需要函数定义。类似的东西(确保适当的缩进):

I just tried your code and with a little modification it works fine. Remove the 'end' statement at the bottom of the file. You also need your function definition before the call to it. Something like (ensure proper indentation):
def display_board(board):
    print(" | | ")
    print(" "+board[6]+" "'|'" "+board[7]+" "'|'" "+board[8]+" ")
    print('------------')
    print(" | | ")
    print(" "+board[3]+" "'|'" "+board[4]+" "'|'" "+board[5]+" ")
    print('------------')
    print(" | | ")
    print(" "+board[0]+" "'|'" "+board[1]+" "'|'" "+board[2]+" ")

test_board = ['1','2','3','4','5','6','7','8','9']
display_board(test_board)


这篇关于运行以下代码时,我收到以下错误 - “list”对象不可调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆