Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Created January 6, 2021 03:40
Show Gist options
  • Save ZechCodes/480f8519d76b36dedfe32753789d9ab3 to your computer and use it in GitHub Desktop.
Save ZechCodes/480f8519d76b36dedfe32753789d9ab3 to your computer and use it in GitHub Desktop.
Challenge 159 - Face Interval

Challenge 159 - Face Interval

In mathematics, interval is the difference between the largest number and the smallest number in a list.

To illustrate:

A = (3, 5, 7, 23, 11, 42, 80)

Interval of A = 80 - 3 = 77

Create a function that takes a list and returns ":)" if the interval of the list is equal to any other element; otherwise return ":(".

Examples

face_interval([1, 2, 5, 8, 3, 9]) ➞ ":)"
# List interval is equal to one of the other elements.

face_interval([5, 2, 8, 3, 11]) ➞ ":("
# List interval is not among the other elements.

Notes

  • Lists won't contain any duplicate numbers.
from __future__ import annotations
import unittest
def face_interval(numbers: list[int]) -> str:
return "" # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertEqual(face_interval([1, 2, 5, 8, 3, 9]), ":)")
def test_2(self):
self.assertEqual(face_interval([5, 2, 6, 3, 11]), ":(")
def test_3(self):
self.assertEqual(face_interval([20, 50, 13, 60, 79, 72, 99]), ":(")
def test_4(self):
self.assertEqual(face_interval([11, 42, 83, 28, 47, 94]), ":)")
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment