| Total Complexity | 2 |
| Total Lines | 21 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | def checkio(data): |
||
| 2 | data = sorted(data) |
||
| 3 | index = len(data) / 2 |
||
| 4 | if index == int(index): |
||
| 5 | index = int(index) |
||
| 6 | return (data[index] + data[index - 1]) / 2 |
||
| 7 | else: |
||
| 8 | return data[int(index)] |
||
| 9 | |||
| 10 | |||
| 11 | # These "asserts" using only for self-checking and not necessary for |
||
| 12 | # auto-testing |
||
| 13 | if __name__ == '__main__': # pragma: no cover |
||
| 14 | assert checkio([1, 2, 3, 4, 5]) == 3, "Sorted list" |
||
| 15 | assert checkio([3, 1, 2, 5, 3]) == 3, "Not sorted list" |
||
| 16 | assert checkio([1, 300, 2, 200, 1]) == 2, "It's not an average" |
||
| 17 | assert checkio([3, 6, 20, 99, 10, 15]) == 12.5, "Even length" |
||
| 18 | print("Start the long test") |
||
| 19 | assert checkio(list(range(1_000_000))) == 499_999.5, "Long." |
||
| 20 | print("The local tests are done.") |
||
| 21 |