Python 官方文档:入门教程 => 点击学习
#-*- coding:utf-8 -*-# 要求输出如下:# apples Alice dogs# dranges Bob cats# cherries Carol moose# banana David G
#-*- coding:utf-8 -*-
# 要求输出如下:
# apples Alice dogs
# dranges Bob cats
# cherries Carol moose
# banana David Goose
tableData=[['apples','oranges','cherries','banana'],
['Alice','Bob','Carol','David'],
['dogs','cats','moose','goose']]
def printTable(data):
colWidths=[0]*len(data)
for y in range(len(data[0])):
for x in range(len(data)):
if colWidths[x] < len(data[x][y]):
colWidths[x]=len(data[x][y])
for y in range(len(data[0])):
for x in range(len(data)):
if x==0:
print(data[x][y].rjust(colWidths[x]),end=' ')
else:
print(data[x][y].ljust(colWidths[x]),end=' ')
print()
printTable(tableData)
--结束END--
本文标题: 《Python编程快速上手》6.7实践项
本文链接: https://lsjlt.com/news/187356.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0