<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def last_heart_rate(self):
 """Return avg heart rate for last session."""

        try:
            rates = self.intervals[1]['timeseries']['heartRate']
        except KeyError:
            return None
        tmp = 0
        num_rates = len(rates)

        if num_rates == 0:
            return None

        for rate in rates:
            tmp += rate[1]
        rateavg = tmp/num_rates
        return rateavg