淘先锋技术网

首页 1 2 3 4 5 6 7

田字格输出python使用print?

python用print()函数输出田字格示例代码如下:

#!/usr/bin/env python

# -*- coding: utf-8 -*-

# Python用print()函数输出田字格

row = ''

for i in range(1, 12):

for j in range(1, 12):

if i in (1, 6, 11):

if j in (1, 6, 11):

row = row + '+' + ' '

else:

row = row + '--' + ' '

else:

if j in (1, 6, 11):

row = row + '|' + ' '

else:

row = row + ' ' + ' '

row = row + '\n'

print row