2016-10-26 126 views
-3

位置我需要爲創建網格中的波紋管位置的網格10隱藏X的如何創建有蟒蛇

# Visible grid 
    v_grid = [] 

    for x in range(8): 
     v_grid.append([]) 
     for y in range(8): 
      v_grid[x].append('[]') 


    def print_v_grid(v_grid): 
     for x in v_grid: 
      print " ".join(x) 
+0

你看過[numpy](http://www.numpy.org/)嗎? – ASGM

+3

那麼,你的問題是什麼? – Kevin

+0

問題我如何創建一個8×8的網格,其中有10個隱藏的x,其中有suer必須找到 –

回答

1

我預計將有至少你問一個問題,但我認爲你需要的是目Python中的網格函數。作爲一個例子:

>>> import numpy as np 
>>> x = np.array([0, 1, 2, 3, 4, 5 , 6, 7, 8, 9]) 
>>> y = np.array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) 
>>> XX, YY = np.meshgrid(x, y) 
>>> N= XX + YY 
>>> print N 

輸出:

([[10 11 12 13 14 15 16 17 18 19] 
[11 12 13 14 15 16 17 18 19 20] 
[12 13 14 15 16 17 18 19 20 21] 
[13 14 15 16 17 18 19 20 21 22] 
[14 15 16 17 18 19 20 21 22 23] 
[15 16 17 18 19 20 21 22 23 24] 
[16 17 18 19 20 21 22 23 24 25] 
[17 18 19 20 21 22 23 24 25 26] 
[18 19 20 21 22 23 24 25 26 27] 
[19 20 21 22 23 24 25 26 27 28]])` 

編輯: 你的代碼是正確的只需要一個命令print print_v_grid末,以顯示你的8 * 8格是這樣的:

x x x x x x x x 
x x x x x x x x 
x x x x x x x x 
x x x x x x x x 
x x x x x x x x 
x x x x x x x x 
x x x x x x x x 
x x x x x x x x 
+0

你可以告訴我你運行它時得到的結果嗎? –

+0

這段代碼的輸出已經包含了,它是一個10 * 10的網格。 – Ssein

+0

當我打印是我得到這個。如何將隱藏的x添加到網格的[]中的一個[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [ [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [ ] –