为了账号安全,请及时绑定邮箱和手机立即绑定

python3的三目运算怎么写?下面的写法为什么错误?

python3的三目运算怎么写?下面的写法为什么错误?

lcycq 2017-06-05 10:24:35
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59 }def generate_tr(name, score):    return score<60?'<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score):'<tr><td>%s</td><td>%s</td></tr>' % (name, score)    # if score < 60:    #     return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score)    # else:    #     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>'
查看完整描述

1 回答

已采纳
?
产品经理不是经理

TA贡献481条经验 获得超143个赞

python是这样写的。
def generate_tr(name, score):
    return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score) if score<60 else '<tr><td>%s</td><td>%s</td></tr>' % (name, score)

查看完整回答
反对 回复 2017-06-05
  • 1 回答
  • 0 关注
  • 1470 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信