實現可多樣化,這樣居然不讓通過
d = { 'Adam': 90, 'Lisa': 55, 'Bart': 59 }
def generate_tr(name, score):
? ? if score < 60:
? ? ? ? score = '<font color="red">%s</font>' % score
? ? return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
tds = [generate_tr(name,score) for name, score in d.iteritems()]
print '<table border="1">'
print '<tr><th>Name</th><th>Score</th><tr>'
print '\n'.join(tds)
print '</table>'
#可以在generate_rt()函數里判斷score然后重新賦值score
2015-12-24
雖然多樣化,但是它要求用css style 屬性。這就沒辦法了