dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
2.0 KiB
2.0 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 69738771fb5a7b8b24cca2a5 | Challenge 179: Pocket Change | 29 | challenge-179 |
--description--
Given an array of integers representing the coins in your pocket, with each integer being the value of a coin in cents, return the total amount in the format "$D.CC".
- 100 cents equals 1 dollar.
- In the return value, include a leading zero for amounts less than one dollar and always exactly two digits for the cents.
--hints--
count_change([25, 10, 5, 1]) should return "$0.41".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(count_change([25, 10, 5, 1]), "$0.41")`)
}})
count_change([25, 10, 5, 1, 25, 10, 25, 1, 1, 10, 5, 25]) should return "$1.43".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(count_change([25, 10, 5, 1, 25, 10, 25, 1, 1, 10, 5, 25]), "$1.43")`)
}})
count_change([100, 25, 100, 1000, 5, 500, 2000, 25]) should return "$37.55".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(count_change([100, 25, 100, 1000, 5, 500, 2000, 25]), "$37.55")`)
}})
count_change([10, 5, 1, 10, 1, 25, 1, 1, 5, 1, 10]) should return "$0.70".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(count_change([10, 5, 1, 10, 1, 25, 1, 1, 5, 1, 10]), "$0.70")`)
}})
count_change([1]) should return "$0.01".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(count_change([1]), "$0.01")`)
}})
count_change([25, 25, 25, 25]) should return "$1.00".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(count_change([25, 25, 25, 25]), "$1.00")`)
}})
--seed--
--seed-contents--
def count_change(change):
return change
--solutions--
def count_change(change):
total_cents = sum(change)
dollars = total_cents // 100
cents = total_cents % 100
return f"${dollars}.{cents:02d}"