<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _calculate_day_cost(self, plan, period):
 """ Finds most fitted plan pricing for a given period, and calculate day cost """


        plan_pricings = plan.planpricing_set.order_by('-pricing__period').select_related('pricing')
        selected_pricing = None
        for plan_pricing in plan_pricings:
            selected_pricing = plan_pricing
            if plan_pricing.pricing.period <= period:
                break

        if selected_pricing:
            return (selected_pricing.price / selected_pricing.pricing.period).quantize(Decimal('1.00'))

        raise ValueError('Plan %s has no pricings.' % plan)