I have a series of rules that I want to be able to execute without having to manually edit the code. I'd like to give my rule conditions at the beginning and have the program run it. This way, I can test every single rule combination in a for loop as well.

Here is a visual example of what I'm trying to do:

firstlist = ["Eat","Chew","Both"]
secondlist = ["Swallow","Spit","None"]
thirdlist = ["Punch","Kick","Push"]

if firstitem == "Eat":
          foodvalue = 4
          if seconditem == "swallow":
                     secondfood = 9
                     if thirditem = "Kick":
                               losecalories = 6

output = foodvalue - secondfood + losecalories

The rules interact with each other so that the output depends on the combination of those rules. Is there any way I can make this dynamic? So that I can have one generic function that will translate all my inputs into one output no matter what I use?

I'm just going to create a function for each rule and have the inputs of that function in nested for loops to produce various combinations.

If anyone has any other suggestions, I'd be interested in seeing them.

Not sure if you have used classes at all yet, but seems logical to use one for what you are doing. I'm posting an example that hopefully doesn't hurt your head to bad. But you can also just run it to see if this is the kind of functionality you are looking for, and just learn classes from a tutorial or something.

class person(object):  #create class named person
#-------these are attributes or things the class has----------

    name = ""    #name is an attribute cause people have names
    eyes = 2     # eyes could be one to
    foodvalue = 0 # or any of these things
    secondfood = 0
    calories = 500

#-----these are the methods or things the class can do--------

    #self means they are part of this partiular person
    #because we can have many persons not just one
    def setname(self,sname): #people have to be given a name
        self.name = sname #down in the real program we passed crazy hippie guy
                          #in as the parameter sname to the setname function
    def eat(self):
        print "mmmmm I'm eating"
        self.foodvalue += 4
    def chew(self):
        print
    def swallow(self):
        print "gulp"
        self.secondfood += 9
    def spit(self):
        print
    def punch(self):
        print
    def kick(self):
        print "hiiiyahhh"
        self.calories -= 6
    def push(self):
        print


x = person()  #here we are creating an instance of a person into variable x

x.setname("crazy hippie guy") #now we can use the . or dot operator to use
                              #the attributes and methods here we call the
                              #setname meathod and give the person a name
#example of the looping
count = 0
while count < 5:
    x.eat()
    count += 1
x.swallow()
x.swallow()
x.kick()

print "This guys name is " + x.name  #now we can print out attributes from the
                                     #crazy guy to see what we have
print "foodvalue = ", x.foodvalue, "secondfood = ", x.secondfood
print "calories = ", x.calories
This question has already been answered. Start a new discussion instead.