defprintUnivlist(ulist, num): print("{:^10}\t{:^6}\t{:^10}".format("排名","学校","总分")) for i inrange(num): u = ulist[i] print("{:^10}\t{:^6}\t{:^10}".format(u[0],u[1],u[2]))
defprintUnivlist(ulist, num): print("{:^10}\t{:^6}\t{:^10}".format("排名","学校","总分")) for i inrange(num): u = ulist[i] print("{:^10}\t{:^6}\t{:^10}".format(u[0],u[1],u[2]))
'''def printUnivlist(ulist, num): print("{:^10}\t{:^6}\t{:^10}".format("排名","学校","总分")) for i in range(num): u = ulist[i] print("{:^10}\t{:^6}\t{:^10}".format(u[0],u[1],u[2])) ''' '''优化输出格式,中文对齐问题,使用chr(12288)表示一个中文空格,utf-8编码''' defprintUnivlist(ulist, num): tplt = "{0:^10}\t{1:{3}^10}\t{2:^10}"#输出模板,{3}使用format函数第三个变量进行填充,即使用中文空格进行填充 print(tplt.format("排名","学校","总分",chr(12288))) for i inrange(num): u = ulist[i] print(tplt.format(u[0],u[1],u[2],chr(12288)))