擅长:python、mysql、java
<p>你可以这样做:</p>
<pre><code>def make_square(inp):
square = " {0} |{1}\t|{2}\n_____________\n {3} | {4}\t|{5}\n_____________\n {6} |{7}\t|{8}" # set {} brackets for 'X' format
inp += -1 # rest because need take from 0 as the brackts indice
for x in range(9): # range max of 'X'
if x != inp:
square = square.replace('{{{0}}}'.format(x),' ') # delete brackets without the number select by the user
# {{ {0} }} explication http://stackoverflow.com/a/5466478/4941927
square = square.replace('{{{0}}}'.format(inp),'{0}') # convert current {number} into {0} for format
square = square.format('X') # formatting brackets for the 'X'
print square
make_square(2)
</code></pre>
<p>如果你需要帮助,我很乐意帮忙
问候语!你知道吗</p>