Home>
code
strings ='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
k = input ('What number element do I want to display?')
n = int (k) -1
print (strings [n])
I want to solve

I want to prevent an error even if I type in a number outside the range

Error message
IndexError Traceback (most recent call last)
<ipython-input-22-15f71847fc50>in<module>
      2 k = input ('What number element do I want to display?')
      3 n = int (k) -1
---->4 print (strings [n])
IndexError: string index out of range
What I tried
strings ='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
k = input ('What number element do I want to display?')
n = int (k) -1
if k<27:
    print (strings [n])
else: else:
    print ('out of range')