Search code examples
pythonfunctionotree

I am trying to add a value , when a person have the right answer


I am trying to make a code in Python for a Otree aplication.

The main idea is to add $20 to a fixed payment when a person have the same answer that I put in my constants.

For example in this code I have a value of 3 in Constants.retemv if a person put a response of 3 in the J11 form the will get the $20

I try to use the next code, payment is a constant with a $20 value.

def set_payoff(self):
        self.payoff = Constants.participation_fee + Constants.iat 
        if self.J11 == Constants.retemv:
            self.payoff += Constants.payment

I expect the output of $45 when the people put the same answer that my retemv”


Solution

  • This is probably what you are looking for:

    def set_payoff(self):
        if self.J11 == Constants.retemv:
            self.payoff = Constants.participation_fee + Constants.iat + Constants.payment
        else:
            self.payoff = Constants.participation_fee + Constants.iat