马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#coding = utf-8
def printf_head():
'''
+----------+-------+
|item |data |
+----------+-------+
'''
name_width = 30
data_width = 10
name_str = ' Item'
data_str = ' Data'
name_strlen = len(name_str)
data_strlen = len(data_str)
if name_strlen >= name_width:
name_str = name_str[:name_width]
else:
filling_name = name_width - name_strlen
if data_strlen >= data_width:
data_str = data_str[:data_width]
else:
filling_data = data_width - data_strlen
print('+{0}+{1}+'.format('-'*name_width,'-'*data_width))
print('|{na}{nlen}|{da}{dlen}|'.format(na=name_str,nlen=' '*filling_name,
da=data_str,dlen=' '*filling_data))
print('+{0}+{1}+'.format('-'*name_width,'-'*data_width))
def printf_data(name_str,data_str):
'''
| | |
'''
name_width = 30
data_width = 10
#add str 'spaces'
name_str = ' '+name_str
data_str = ' '+data_str
name_strlen = len(name_str)
data_strlen = len(data_str)
if name_strlen >= name_width:
name_str = name_str[:name_width]
filling_name = name_width - name_strlen
else:
filling_name = name_width - name_strlen
if data_strlen >= data_width:
data_str = data_str[:data_width]
filling_data = data_width - data_strlen
else:
filling_data = data_width - data_strlen
print('|{na}{nlen}|{da}{dlen}|'.format(na=name_str,nlen=' '*filling_name,
da=data_str,dlen=' '*filling_data))
def printf_end():
'''
+----------+-------+
'''
name_width = 30
data_width = 10
print('+{0}+{1}+'.format('-'*name_width,'-'*data_width))
# name = input('Please input string:')
# data = input('Please input data:')
printf_head()
name = ['gin','lsp','dhg','ht','lnn']
data = (170,160,165,172,170)
for x,j in zip(name,data):
printf_data(x,str(j))
printf_end()
+------------------------------+----------+
| Item | Data |
+------------------------------+----------+
| gin | 170 |
| lsp | 160 |
| dhg | 165 |
| ht | 172 |
| lnn | 170 |
+------------------------------+----------+
请按任意键继续. . .
|