Пример #1
0
    def test_median(self):
        self.assertRaises(IndexError, find_median, [])
        sequence = [5, 9, 3, 4, 6, 2, 8, 7, 1]
        copy = [x for x in sequence]
        self.assertEqual(5, find_median(sequence))
        self.assertEqual(copy, sequence)

        sequence = [5, 9, 3, 4, 6, 2, 0, 8, 7, 1]
        copy = [x for x in sequence]
        self.assertIn(find_median(sequence), [4, 5])
        self.assertEqual(copy, sequence)
Пример #2
0
def main():
    sequence = [5, 9, 3, 4, 6, 2, 0, 8, 7, 1]
    print(find_median(sequence))
Пример #3
0
def main(filename):
    with open(filename, 'r') as reader:
        text = [line.strip() for line in reader]
        median = find_median(text)
        print('Median:', median)