Fun and Puzzles

his project involves programming the bill dispenser subsystem for an ATM. Use this project to improve your function-writing skills.

All our Data Science projects include bite-sized activities to test your knowledge and practice in an environment with constant feedback.

All our activities include solutions with explanations on how they work and why we chose them.

codevalidated

Write the function `calculate_bills_to_use`

that returns a dictionary with the bill denomination and how many bills to use. Examples:

```
>>> calculate_bills_to_use(843)
{500: 1, 100: 3, 50: 0, 25: 1, 10: 1, 5: 1, 1: 3}
>>> calculate_bills_to_use(1763)
{500: 3, 100: 2, 50: 1, 25: 0, 10: 1, 5: 0, 1: 3}
>>> calculate_bills_to_use(177)
{500: 0, 100: 1, 50: 1, 25: 1, 10: 0, 5: 0, 1: 2}
>>> calculate_bills_to_use(355)
{500: 0, 100: 3, 50: 1, 25: 0, 10: 0, 5: 1, 1: 0}
>>> calculate_bills_to_use(10_988)
{500: 21, 100: 4, 50: 1, 25: 1, 10: 1, 5: 0, 1: 3}
```

codevalidated

Write the function `calculate_bills_to_use_advanced`

that receives two parameters: the amount to withdraw, and a dictionary with bills and their availability. For example:

```
# There are no $100 bills
>>> calculate_bills_to_use_advanced(163, {
500: 1,
100: 0,
50: 10,
25: 10,
10: 10,
5: 10,
1: 10
})
{500: 0, 100: 0, 50: 3.0, 25: 0, 10: 1.0, 5: 0, 1: 3.0}
# There are no $100 or $10 bills
>>> calculate_bills_to_use_advanced(163, {
500: 1,
100: 0,
50: 10,
25: 10,
10: 0,
5: 10,
1: 10
})
{500: 0, 100: 0, 50: 3.0, 25: 0, 10: 0, 5: 2.0, 1: 3.0}
```

This project is part of

Explore other projects