Encodes to Baconian cipher >>> encode("hello") 'AABBBAABAAABABAABABAABBAB' >>> encode("hello world") 'AABBBAABAAABABAABABAABBAB BABAAABBABBAAAAABABAAAABB' >>> encode("hello world!") Traceback (most recent call last): ... Exception: encode() accepts only lett
(word: str)
| 38 | |
| 39 | |
| 40 | def encode(word: str) -> str: |
| 41 | """ |
| 42 | Encodes to Baconian cipher |
| 43 | |
| 44 | >>> encode("hello") |
| 45 | 'AABBBAABAAABABAABABAABBAB' |
| 46 | >>> encode("hello world") |
| 47 | 'AABBBAABAAABABAABABAABBAB BABAAABBABBAAAAABABAAAABB' |
| 48 | >>> encode("hello world!") |
| 49 | Traceback (most recent call last): |
| 50 | ... |
| 51 | Exception: encode() accepts only letters of the alphabet and spaces |
| 52 | """ |
| 53 | encoded = "" |
| 54 | for letter in word.lower(): |
| 55 | if letter.isalpha() or letter == " ": |
| 56 | encoded += encode_dict[letter] |
| 57 | else: |
| 58 | raise Exception("encode() accepts only letters of the alphabet and spaces") |
| 59 | return encoded |
| 60 | |
| 61 | |
| 62 | def decode(coded: str) -> str: |
nothing calls this directly
no outgoing calls
no test coverage detected