Returns True if number is bouncy, False otherwise >>> check_bouncy(6789) False >>> check_bouncy(-12345) False >>> check_bouncy(0) False >>> check_bouncy(6.74) Traceback (most recent call last): ... ValueError: check_bouncy() accepts only in
(n: int)
| 18 | |
| 19 | |
| 20 | def check_bouncy(n: int) -> bool: |
| 21 | """ |
| 22 | Returns True if number is bouncy, False otherwise |
| 23 | >>> check_bouncy(6789) |
| 24 | False |
| 25 | >>> check_bouncy(-12345) |
| 26 | False |
| 27 | >>> check_bouncy(0) |
| 28 | False |
| 29 | >>> check_bouncy(6.74) |
| 30 | Traceback (most recent call last): |
| 31 | ... |
| 32 | ValueError: check_bouncy() accepts only integer arguments |
| 33 | >>> check_bouncy(132475) |
| 34 | True |
| 35 | >>> check_bouncy(34) |
| 36 | False |
| 37 | >>> check_bouncy(341) |
| 38 | True |
| 39 | >>> check_bouncy(47) |
| 40 | False |
| 41 | >>> check_bouncy(-12.54) |
| 42 | Traceback (most recent call last): |
| 43 | ... |
| 44 | ValueError: check_bouncy() accepts only integer arguments |
| 45 | >>> check_bouncy(-6548) |
| 46 | True |
| 47 | """ |
| 48 | if not isinstance(n, int): |
| 49 | raise ValueError("check_bouncy() accepts only integer arguments") |
| 50 | str_n = str(n) |
| 51 | sorted_str_n = "".join(sorted(str_n)) |
| 52 | return str_n not in {sorted_str_n, sorted_str_n[::-1]} |
| 53 | |
| 54 | |
| 55 | def solution(percent: float = 99) -> int: |