擅长:python、mysql、java
<p>我认为这可能至少接近你想要的:</p>
<pre><code>class TreasureMap:
UNSEARCHED_CHAR = '.'
class MyClass:
def __init__(self, size, chests, trees):
self.__treasure_map = size
self.__chest_positions = chests
self.__tree_positions = trees
self.__num_chests_found = 0
self.grid=[]
for i in range(self.__treasure_map):
self.grid.append([])
for j in range(self.__treasure_map):
self.grid[i].append(TreasureMap.UNSEARCHED_CHAR)
def display_map(self):
print(' ', ' '.join(str(i) for i in range(self.__treasure_map)))
for i in range(self.__treasure_map):
print('{:>2}'.format(i), ' '.join(elem for elem in self.grid[i]))
if __name__ == '__main__':
obj = MyClass(5, 1, 2)
obj.display_map()
</code></pre>
<p>输出:</p>
<pre class="lang-none prettyprint-override"><code> 0 1 2 3 4
0 . . . . .
1 . . . . .
2 . . . . .
3 . . . . .
4 . . . . .
</code></pre>