Team1 = ["Red", 10]
Team2 = ["Green", 5]
Team3 = ["Blue", 6]
Team4 = ["Yellow", 8]
Team5 = ["Purple", 9]
Team6 = ["Brown", 4]
TeamList = [Team1, Team2, Team3, Team4, Team5, Team6]
# print the top row of team names, tab separated, starting two tabs over:
print '\t\t', '\t'.join(team[0] for team in TeamList)
# for each row in the chart
for team in TeamList:
# put two tabs between each score difference column
scoreline = '\t\t'.join(str(team[1] - other[1]) for other in TeamList)
# and print the team name, a tab, then the score columns
print team[0], '\t', scoreline
只是使用制表符而不是任何花哨的格式来构建图表:
你可以试试:
它将生成一个嵌套列表,表示建议的输出(当然,没有列标题和行标题)。
您可以尝试嵌套for循环。像这样的事情:
这会给分数差。必须对输出进行格式化,以获得所需的确切表外观。
相关问题 更多 >
编程相关推荐