Hướng dẫn how to create a board in python - cách tạo bảng trong python

xxx
xxx
xxx

Cố gắng tìm cách để thực hiện danh sách 2D này.

Đã hỏi ngày 12 tháng 11 năm 2016 lúc 19:16Nov 12, 2016 at 19:16

Hướng dẫn how to create a board in python - cách tạo bảng trong python

Naraemeenaraemeenaraemee

451 Huy hiệu vàng1 Huy hiệu bạc8 Huy hiệu đồng1 gold badge1 silver badge8 bronze badges

3

Điều này làm việc cho tôi trong khi tạo bảng trò chơi 2048

# creating a board of 4 x 4 size
# initializes a list of lists with 4 rows and 4 columns
board = [ [0] * 4 ] * 4

# for printing the board
for row in board:
print(row)

# the result it produces
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]

Đã trả lời ngày 22 tháng 7 năm 2021 lúc 23:05Jul 22, 2021 at 23:05

Hướng dẫn how to create a board in python - cách tạo bảng trong python

Joyclever thông minh niềm vuiClever Joy

721 Huy hiệu bạc2 Huy hiệu đồng1 silver badge2 bronze badges

Một trong nhiều cách để làm điều đó:

for x in range(row):
    print('x '*col)

Ví dụ:

for x in range(row):
    print('x '*col)
8,
for x in range(row):
    print('x '*col)
9 sau đó xuất ra:

x x x 
x x x 
x x x 

Alternatively,,

Tạo một danh sách-

a=[]
for x in range(0, row):
    a.append(["x"] * col)

Sau đó in nó-

for row in a:
    print " ".join(row)

Đã trả lời ngày 12 tháng 11 năm 2016 lúc 19:36Nov 12, 2016 at 19:36

Ani Menonani MenonAni Menon

25.9K16 Huy hiệu vàng94 Huy hiệu bạc121 Huy hiệu đồng16 gold badges94 silver badges121 bronze badges

3

thử cái này:

def main():
    print("Num of rows:")
    row = int(input())
    print("Num of Cols:")
    columns = int(input())
    print("Out:\n")

    for i in range(row): # iterate in rows
        print('x'*columns) # print 'x' columns times

if __name__ == '__main__':
    main()

Đã trả lời ngày 12 tháng 11 năm 2016 lúc 19:32Nov 12, 2016 at 19:32

Hướng dẫn how to create a board in python - cách tạo bảng trong python

EdcornejoedcornejoEdCornejo

70312 Huy hiệu bạc13 Huy hiệu đồng12 silver badges13 bronze badges

0

21 ví dụ mã Python được tìm thấy liên quan đến "Tạo bảng". Bạn có thể bỏ phiếu cho những người bạn thích hoặc bỏ phiếu cho những người bạn không thích và đi đến dự án gốc hoặc tệp nguồn bằng cách theo các liên kết trên mỗi ví dụ. create board". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

ví dụ 1

def create_agile_board(self, name, type, filter_id, location=None):
        """
        Create an agile board
        :param name: str
        :param type: str, scrum or kanban
        :param filter_id: int
        :param location: dict, Optional. Default is user
        """
        data = {'name': name,
                'type': type,
                'filterId': filter_id}
        if location:
            data['location'] = location
        else:
            data['location'] = {'type': 'user'}
        url = 'rest/agile/1.0/board'
        return self.post(url, data=data) 

Ví dụ 2

def create_board(self):
        """
        Generates an empty Treefinder board, which is what `self.board`
        defaults to.

        :return: A 2D array (self.height * self.width) populated with Tile.EMPTY
        """
        board = []

        for x in range(self.height):
            row = []

            for y in range(self.width):
                row.append(Tile.EMPTY)

            board.append(row)

        return board 

Ví dụ 3

def create_board(self, name, description='', category='other', privacy='public', layout='default'):
        """
        Creates a new board and returns the response from pinterest.
        :param name: board name (should be unique per user)
        :param description: board description
        :param category: if you have defined categories (it is not visible to external users)
        :param privace: can be public or private
        :param layout: looks like a legacy parameter but is it mandatory (can be left as
        """
        options = {
            "name": name,
            "description": description,
            "category": category,
            "privacy": privacy,
            "layout": layout,
            "collab_board_email": 'true',
            "collaborator_invites_enabled": 'true'
        }

        source_url = '/{}/boards/'.format(self.email)
        data = self.req_builder.buildPost(options=options, source_url=source_url)
        return self.post(url=CREATE_BOARD_RESOURCE, data=data) 

Ví dụ 4

# creating a board of 4 x 4 size
# initializes a list of lists with 4 rows and 4 columns
board = [ [0] * 4 ] * 4

# for printing the board
for row in board:
print(row)

# the result it produces
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
0

Ví dụ 5

# creating a board of 4 x 4 size
# initializes a list of lists with 4 rows and 4 columns
board = [ [0] * 4 ] * 4

# for printing the board
for row in board:
print(row)

# the result it produces
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
1

Ví dụ 6

# creating a board of 4 x 4 size
# initializes a list of lists with 4 rows and 4 columns
board = [ [0] * 4 ] * 4

# for printing the board
for row in board:
print(row)

# the result it produces
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
2

Ví dụ 7

# creating a board of 4 x 4 size
# initializes a list of lists with 4 rows and 4 columns
board = [ [0] * 4 ] * 4

# for printing the board
for row in board:
print(row)

# the result it produces
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
3

Ví dụ 8

# creating a board of 4 x 4 size
# initializes a list of lists with 4 rows and 4 columns
board = [ [0] * 4 ] * 4

# for printing the board
for row in board:
print(row)

# the result it produces
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
4

Ví dụ 9

# creating a board of 4 x 4 size
# initializes a list of lists with 4 rows and 4 columns
board = [ [0] * 4 ] * 4

# for printing the board
for row in board:
print(row)

# the result it produces
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
5

Ví dụ 10

# creating a board of 4 x 4 size
# initializes a list of lists with 4 rows and 4 columns
board = [ [0] * 4 ] * 4

# for printing the board
for row in board:
print(row)

# the result it produces
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
6

Ví dụ 11

# creating a board of 4 x 4 size
# initializes a list of lists with 4 rows and 4 columns
board = [ [0] * 4 ] * 4

# for printing the board
for row in board:
print(row)

# the result it produces
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
7

Ví dụ 12

# creating a board of 4 x 4 size
# initializes a list of lists with 4 rows and 4 columns
board = [ [0] * 4 ] * 4

# for printing the board
for row in board:
print(row)

# the result it produces
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
4

Ví dụ 13

# creating a board of 4 x 4 size
# initializes a list of lists with 4 rows and 4 columns
board = [ [0] * 4 ] * 4

# for printing the board
for row in board:
print(row)

# the result it produces
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
9

Ví dụ 14

for x in range(row):
    print('x '*col)
0

Ví dụ 15

for x in range(row):
    print('x '*col)
1

Ví dụ 16

for x in range(row):
    print('x '*col)
2

Ví dụ 17

for x in range(row):
    print('x '*col)
3

Ví dụ 18

for x in range(row):
    print('x '*col)
4

Ví dụ 19

for x in range(row):
    print('x '*col)
5

Ví dụ 20

for x in range(row):
    print('x '*col)
6

Ví dụ 21

for x in range(row):
    print('x '*col)
7