title: Python Efficiency - Better version than multiple if elif statements - use a for loop - chr ord conversions?
body: <p>I'm taking an intro to an online Python course and here's the problem description.</p>
  
  <blockquote>
    <p>Write a program which does the reverse of the example above: it should take a character as input and output the corresponding number (between 1 and 26). Your program should only accept capital letters. As error-checking, print invalid if the input is not a capital letter. </p>
  </blockquote>
  
  <p>Can someone reply with a more efficient way of writing the following?</p>
  
  <pre><code>letter = input()
  x = ord(letter)
  if x &gt;= ord('A') and x == 65:
     print(1)
  elif x &gt;= ord('A') and x == 66:
     print(2)
  elif x &gt;= ord('A') and x == 67:
     print(3)
  elif x &gt;= ord('A') and x == 68:
     print(4)
  elif x &gt;= ord('A') and x == 69:
     print(5)
  elif x &gt;= ord('A') and x == 70:
     print(6)
  elif x &gt;= ord('A') and x == 71:
     print(7)
  elif x &gt;= ord('A') and x == 72:
     print(8)
  
  
  else:
     print("invalid")
  </code></pre>
  
  <p>I was thinking of some kind of for loop. I started several versions of for loops, but can't figure out how to handle the iterator and correspond it to the increasing asci value. Thanks! <a href="http://imgur.com/ggt6mXl" rel="nofollow">This chr ord chart could help</a></p>