:param number: nth hexagonal number to calculate :return: the nth hexagonal number Note: A hexagonal number is only defined for positive integers >>> hexagonal(4) 28 >>> hexagonal(11) 231 >>> hexagonal(22) 946 >>> hexagonal(0) Traceback (most recent call
(number: int)
| 12 | |
| 13 | |
| 14 | def hexagonal(number: int) -> int: |
| 15 | """ |
| 16 | :param number: nth hexagonal number to calculate |
| 17 | :return: the nth hexagonal number |
| 18 | Note: A hexagonal number is only defined for positive integers |
| 19 | >>> hexagonal(4) |
| 20 | 28 |
| 21 | >>> hexagonal(11) |
| 22 | 231 |
| 23 | >>> hexagonal(22) |
| 24 | 946 |
| 25 | >>> hexagonal(0) |
| 26 | Traceback (most recent call last): |
| 27 | ... |
| 28 | ValueError: Input must be a positive integer |
| 29 | >>> hexagonal(-1) |
| 30 | Traceback (most recent call last): |
| 31 | ... |
| 32 | ValueError: Input must be a positive integer |
| 33 | >>> hexagonal(11.0) |
| 34 | Traceback (most recent call last): |
| 35 | ... |
| 36 | TypeError: Input value of [number=11.0] must be an integer |
| 37 | """ |
| 38 | if not isinstance(number, int): |
| 39 | msg = f"Input value of [number={number}] must be an integer" |
| 40 | raise TypeError(msg) |
| 41 | if number < 1: |
| 42 | raise ValueError("Input must be a positive integer") |
| 43 | return number * (2 * number - 1) |
| 44 | |
| 45 | |
| 46 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected