Shift Characters with ord/chr

Medium ⏱ 12 min 48% acceptance ★★★★★ 4.9
Write shift_char_codes(s, shift) that returns a new string where every character's Unicode code point is increased by shift, using ord() to read a code point and chr() to convert it back. No wraparound is needed — this problem is about the ord/chr mechanics, not a full cipher.

Examples

Example 1
Input
s = 'abc', shift = 1
Output
'bcd'
Explanation

ord('a')=97, +1=98 which is chr 'b', and so on for each character.

Example 2
Input
s = 'AAA', shift = 2
Output
'CCC'
Explanation

Each 'A' (65) becomes 67, which is 'C'.

Constraints

  • shift can be any integer such that results stay within valid Unicode code points.

Topics

StringsEncoding Basics

Companies

CiscoIntel

Hints

Hint 1

`chr(ord(c) + shift)` transforms one character.

Hint 2

Apply it to every character with a generator expression inside `''.join(...)`.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.