How do I generate PuLP variables and constrains without using exec?
问题 I have written the following Python Code using the PuLP Library for solving the Knapsack Problem using the Integer Programming formulation. I am using strings to generate the LpVariable commands and add the constraints and then executing them with eval. Is there a way to do this without using eval? from pulp import * #Knapsack problem items = input ('Enter the number of items :') items = int(items) #print('Enter %d items one by one') print ('Enter {0} items profit one by one'.format(items))