3
我怎麼能簡化下面的Python紙漿語句到的東西更Python,管理和糾正:如何簡化重複的Python PuLP語法?
import pulp as lp
#delare variables
#Note that I have to model a 100 year period!
year_1 = lp.LpVariable("2011", 0, None, lp.LpInteger)
year_2 = lp.LpVariable("2012", 0, None, lp.LpInteger)
year_. = lp.LpVariable("201.", 0, None, lp.LpInteger)
year_n = lp.LpVariable("201n", 0, None, lp.LpInteger)
#declare constraints
prob += year_1 - year_0 >= 0
prob += year_2 - year_1 >= 0
prob += year_. - year_. >= 0
prob += year_n - year_n_1 >= 0