---
id: 6a15cadf5f240d05a2649556
title: "Challenge 312: Streaming Cost"
challengeType: 29
dashedName: challenge-312
---

# --description--

Given an array representing movies in the cart of your streaming service, and a string for your subscription tier, return the total cost of the movies.

Each item in the cart is an object with a `"format"` (`"HD"` or `"4K"`) and a `"type"` (`"rent"` or `"buy"`). Their costs are:

| | `"rent"` | `"buy"` |
| - | - | - |
| `"HD"` | $3.99 | $12.99 |
| `"4K"` | $5.99 | $19.99 |

Apply the following subscription tier discounts:

- `"none"`: full price
- `"basic"`: 10% off
- `"premium"`: 25% off

Return the total cost rounded to two decimal places in the format `"$D.CC"`.

# --hints--

`get_streaming_bill([{ "format": "HD", "type": "rent" }], "none")` should return `"$3.99"`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_streaming_bill([{"format": "HD", "type": "rent"}], "none"), "$3.99")`)
}})
```

`get_streaming_bill([{ "format": "HD", "type": "buy" }], "premium")` should return `"$9.74"`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_streaming_bill([{"format": "HD", "type": "buy"}], "premium"), "$9.74")`)
}})
```

`get_streaming_bill([{ "format": "HD", "type": "rent" }, { "format": "HD", "type": "rent" }, { "format": "HD", "type": "buy" }], "basic")` should return `"$18.87"`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_streaming_bill([{"format": "HD", "type": "rent"}, {"format": "HD", "type": "rent"}, {"format": "HD", "type": "buy"}], "basic"), "$18.87")`)
}})
```

`get_streaming_bill([{ "format": "4K", "type": "buy" }, { "format": "4K", "type": "buy" }, { "format": "4K", "type": "buy" }], "premium")` should return `"$44.98"`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_streaming_bill([{"format": "4K", "type": "buy"}, {"format": "4K", "type": "buy"}, {"format": "4K", "type": "buy"}], "premium"), "$44.98")`)
}})
```

`get_streaming_bill([{ "format": "HD", "type": "rent" }, { "format": "4K", "type": "rent" }, { "format": "HD", "type": "buy" }, { "format": "4K", "type": "buy" }], "none")` should return `"$42.96"`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_streaming_bill([{"format": "HD", "type": "rent"}, {"format": "4K", "type": "rent"}, {"format": "HD", "type": "buy"}, {"format": "4K", "type": "buy"}], "none"), "$42.96")`)
}})
```

`get_streaming_bill([{ "format": "HD", "type": "rent" }, { "format": "4K", "type": "rent" }, { "format": "HD", "type": "buy" }, { "format": "4K", "type": "buy" }], "basic")` should return `"$38.66"`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_streaming_bill([{"format": "HD", "type": "rent"}, {"format": "4K", "type": "rent"}, {"format": "HD", "type": "buy"}, {"format": "4K", "type": "buy"}], "basic"), "$38.66")`)
}})
```

# --seed--

## --seed-contents--

```py
def get_streaming_bill(cart, subscription):

    return cart
```

# --solutions--

```py
def get_streaming_bill(cart, subscription):
    pricing = {
        "HD": {"rent": 3.99, "buy": 12.99},
        "4K": {"rent": 5.99, "buy": 19.99},
    }
    discounts = {"none": 1, "basic": 0.9, "premium": 0.75}
    multiplier = discounts[subscription]
    total = sum(pricing[item["format"]][item["type"]] * multiplier for item in cart)
    return f"${total:.2f}"
```
