Python Forum
ord() - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: ord() (/thread-36037.html)



ord() - Men - Jan-12-2022

Hi,

Quick question. coding in python...How do you continuously decrease an ord value until it reaches an n value?

for example: i have a ord value of 104 which is 'h' and want to move and change it to the previous letter g then loop back change g to f until I reach 97 which is 'a'.

Thx in advance for your help.

Cheers


RE: ord() - Gribouillis - Jan-12-2022

Try
for i in range(104, 96, -1):
    print(chr(i))



RE: ord() - Men - Jan-12-2022

Thanks a lot that works great...now I have to figure out how to place it in a variable.
Cheers,

(Jan-12-2022, 06:46 AM)Gribouillis Wrote: Try
for i in range(104, 96, -1):
    print(chr(i))