Find excess-3 code of integer base 10. Add 3 to all digits in a decimal number then convert to a binary-coded decimal. https://en.wikipedia.org/wiki/Excess-3 >>> excess_3_code(0) '0b0011' >>> excess_3_code(3) '0b0110' >>> excess_3_code(2) '0b0101' >>> excess
(number: int)
| 1 | def excess_3_code(number: int) -> str: |
| 2 | """ |
| 3 | Find excess-3 code of integer base 10. |
| 4 | Add 3 to all digits in a decimal number then convert to a binary-coded decimal. |
| 5 | https://en.wikipedia.org/wiki/Excess-3 |
| 6 | |
| 7 | >>> excess_3_code(0) |
| 8 | '0b0011' |
| 9 | >>> excess_3_code(3) |
| 10 | '0b0110' |
| 11 | >>> excess_3_code(2) |
| 12 | '0b0101' |
| 13 | >>> excess_3_code(20) |
| 14 | '0b01010011' |
| 15 | >>> excess_3_code(120) |
| 16 | '0b010001010011' |
| 17 | """ |
| 18 | num = "" |
| 19 | for digit in str(max(0, number)): |
| 20 | num += str(bin(int(digit) + 3))[2:].zfill(4) |
| 21 | return "0b" + num |
| 22 | |
| 23 | |
| 24 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected