#! python3
tableData = [['apples','oranges','cherries','banana'],
['Alice','Bob','Carol','David'],
['dogs','cats','moose','goose']]
# apples Alice dogs
# dranges Bob cats
# cherries Carol moose
# banana David goose
def printTable():
colWidths = [0] * len(tableData)
for x in range(len(tableData)):
for y in range(len(tableData[0])):
if len(tableData[x][y]) > colWidths[x]:
colWidths[x] = len(tableData[x][y])
for i in range(len(tableData[0])):
for j in range(len(colWidths)):
print(tableData[j][i].rjust(colWidths[j]), end=' ')
print()
printTable()
python编程快速上手 第6章 实践项目参考答案
最新推荐文章于 2022-07-11 13:22:02 发布