Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Created November 13, 2020 03:06
Show Gist options
  • Save ZechCodes/569bf4c10c1ac95e6ba9c1795f1109c2 to your computer and use it in GitHub Desktop.
Save ZechCodes/569bf4c10c1ac95e6ba9c1795f1109c2 to your computer and use it in GitHub Desktop.
Challenge 148 - Calculate Uncovered

Challenge 148 - Calculate Uncovered

Someone stole some of your stuff. You have insurance that will cover the cost to replace them up to a certain limit. Create a function that returns the amount that isn't covered when given a limit and a dictionary of all stolen items and their value. If the insurance covers the cost of all items then return 0.

Examples

calc_uncovered({ "baseball bat": 20 }, 5) ➞ 15

calc_uncovered({"skate": 10, "painting": 20 }, 19) ➞ 11

calc_uncovered({"skate": 200, "painting": 200, "shoes": 1 }, 400) ➞ 1

Notes

  • The dict data always contains at least an item (no empty objects).
from __future__ import annotations
import unittest
def calc_uncovered(stolen_items: dict[str, int], coverage_limit: int) -> int:
return 0 # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertEqual(25001, calc_uncovered({"skate": 20000, "painting": 30000, "shoes": 1}, 25000))
def test_2(self):
self.assertEqual(11, calc_uncovered({"baseball bat": 31}, 20))
def test_3(self):
self.assertEqual(0, calc_uncovered({"stereo": 1110, "pillow": 25}, 5000))
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment