osodg
April 7, 2024, 1:49pm
1
need help with the final formula. Can some one help me come up with the correct calculations.
Here is my try with python (my preferred language). My formula does not work. Need help with my math.

```
def price_discounted(ratePerHour, numDays, discount):
discounted_months = numDays//22
reg_days = numDays%22
discounted_rate = discounted_months * 22 * 8 * ratePerHour * discount
reg_rate = reg_days * 8 * ratePerHour
return round(discounted_rate + reg_rate)
print(price_discounted(89, 230, 0.42))
```

IsaacG
April 7, 2024, 2:23pm
2
I believe you are applying the discount incorrectly.

osodg
April 7, 2024, 2:39pm
3
Yeah, My math is not so good.

osodg
April 7, 2024, 3:57pm
4
This is my best try:

```
export function priceWithMonthlyDiscount(ratePerHour, numDays, discount) {
full_months = Math.floor(numDays / 22);
remaining_days = numDays % 22;
full_months_discounted_rate = full_months * 22 * 8 * ratePerHour * (1 - discount);
remaining_days_regular_rate = remaining_days * 8 * ratePerHour;
total_cost = full_months_discounted_rate + remaining_days_regular_rate;
return math.ceil(total_cost);
}
```

still not passing the test