0

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”

  • There is not enough context to figure out what is going on in your question. you don't provide the actual answer. Please consider adding more details to your question. – LhasaDad Oct 13 '19 at 03:13
  • I am sorry, I try adding some context. – Sebastián Ramírez Oct 13 '19 at 03:20
  • 1
    I think your issue is that you are trying to initialize the `payoff` attribute in a function that is probably called more than once which will always reset the value in payoff even after the `J11` was one time equal to `retemv`, are you sure payoff isn't something that should be in `__init__()`? – Moshe Rabaev Oct 13 '19 at 03:52

1 Answers1

0

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 
Antonio
  • 158
  • 1
  • 14