Write a function
shiftLetter(letter, n)
whose parameter, letter
should be a single character. If the character is between "A"
and "Z"
, the function returns an upper case character
n
positions further along, and "wrapping" if the +
n
mapping goes past "Z"
. Likewise, it should map the lower case characters between "a"
and "z"
. If the parameter letter
is anything else, or not of length 1, the function should return letter
.
Hint: review functions ord()
and chr()
from the section, as well as the modulus operator %
.
Down below is what I worked so far. It should return to A after alphabet is over, but it's not working properly from alphabet x. I guess..? I should subtract 90(Z) - 65(A) in ASCII table for x,y,z but confused about that.
def shiftLetter(letter,n):
if letter >= 'A' and letter <= 'Z':
return chr(ord(letter) + n )
elif letter >= 'a' and letter <= 'z':
return chr(ord(letter) + n )
print(shiftLetter('w',3))