2014-03-26 25 views

回答

0

编辑:有人更改了问题的一个关键细节 阿疣winiचhaudhary给出了一个很好的答案。 /如果你是不是在学习的位置使用的String.Format现在则解决问题的更普遍的/算法的方法是这样的:

for (name, score) in students: 
    print '%s%s%s\n'%(name,' '*(10-len(name)),score) 
5

使用string formatting

>>> students = [("Abe", 200), ("Lindsay", 180), ("Rachel" , 215)] 
>>> for a, b in students: 
...  print '{:<7s} {}'.format(a, b) 
... 
Abe  200 
Lindsay 180 
Rachel 215 
0

使用rjust和ljust:

for s in students: 
    print s[0].ljust(8)+(str(s[1])).ljust(3) 

输出:

Abe  200 
Lindsay 180 
Rachel 215