, char z, 1 2,
Example: if you increment z by incr (say incr = 2 or 3), then (chr (ord ('z') + incr)) does not give you an increasing value because the ascii value is out of range.
for the general way that you should do this
i = a to z any character
incr = no. of increment
asci = ord(i)
if (asci >= 97) & (asci <= 122):
asci += incr
if asci > 122 :
asci = asci%122 + 96
if asci < 97:
asci += 26
print chr(asci)
it will work to increase or decrease both.
the same can be done for a capital letter, only the asci value will be changed.
source
share