| Total Complexity | 3 |
| Total Lines | 23 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | def shift_char(char, delta): |
||
| 2 | base_ord = ord('a') |
||
| 3 | return chr(base_ord + (ord(char) - base_ord + delta) % 26) |
||
| 4 | |||
| 5 | |||
| 6 | def to_encrypt(text, delta): |
||
| 7 | char_list = [shift_char(i, delta) if 'a' <= i <= 'z' else i for i in text] |
||
| 8 | return ''.join(char_list) |
||
| 9 | |||
| 10 | |||
| 11 | if __name__ == '__main__': |
||
| 12 | print("Example:") |
||
| 13 | print(to_encrypt('abc', 10)) |
||
| 14 | |||
| 15 | # These "asserts" using only for self-checking |
||
| 16 | # and not necessary for auto-testing |
||
| 17 | assert to_encrypt("a b c", 3) == "d e f" |
||
| 18 | assert to_encrypt("a b c", -3) == "x y z" |
||
| 19 | assert to_encrypt("simple text", 16) == "iycfbu junj" |
||
| 20 | assert to_encrypt("important text", 10) == "swzybdkxd dohd" |
||
| 21 | assert to_encrypt("state secret", -13) == "fgngr frperg" |
||
| 22 | print("Coding complete? Click 'Check' to earn cool rewards!") |
||
| 23 |