<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def weight2codon(self, weight, length=None):
 """ Given a weight between -5 and 5, turn it into a codon, eg "000" to "999" """

        if length is None:
            length = self.clen
        retval = 0
        weight = min(max(weight + 5.0, 0), 10.0) * (10 ** (length - 1))
        for i in range(length):
            if i == length - 1: # last one
                d = int(round(weight / (10 ** (length - i - 1))))
            else:
                d = int(weight / (10 ** (length - i - 1)))
            weight = weight % (10 ** (length - i - 1))
            retval += d * (10 ** (length - i - 1))
        return ("%0" + str(length) + "d") % retval