如何将这两个功能有效地合并为一个

时间:2018-10-20 22:12:21

标签: python python-3.x python-2.7

Its basically changing the color of the html row of the table according to 
the value present in c1...c5. The difference between both the function is 
that, in 2nd function I am trying to add the value of "%".

def get_env(lm,mid,c1,c2,c3,c4,c5):
    global tag
    x = []
    for item in lm:
        rnd_off = round(item)
        x.append(rnd_off)
    tag  += '''<tr><th>'''+mid+'''</th>'''
    for i in hey:
        if i <= c1:
            tag += '<td style="background-color:#229954">' + ' ' +  str(i)  + '</td>'
        elif i > c1 and i <= c2:

Can someone please tell me how can I merge this two function into one correct way with repeating much of code. Thanks for taking a look. I really appreciate your help and thanks in advance.

I can merge the code the but still repeating a little bit of code. Just need to know the correct way of doing that. I really appreciate if someone can put some insight on this. Thanks for taking a look

有人可以告诉我如何通过重复很多代码来合并这种正确的方法。谢谢参观。非常感谢您的帮助,并预先感谢

有人可以告诉我如何通过重复很多代码来合并这种正确的方法。谢谢参观。非常感谢您的帮助,并预先感谢

1 个答案:

答案 0 :(得分:0)

函数应该返回字符串,而不是添加到全局变量。我认为颜色是常量,您真的需要给c1..5作为参数吗? 我认为import {withRouter} from 'react-router-dom` class NavComponent extends React.Component { render(){ return ( <Router> <NavLink className='sign-up' to='/build/signup'>Register</NavLink> </Router> ) } } export default withRouter(NavComponent); 未定义,应该是hey

lm