title: How to print words from a word list that have 5 letters or less Python 2.7?
body: <p>I'm sorta new to python, which you can probably see by my crappy coding below. If you were to play this game, you would probably find that it's really hard, so to make it easier, I want to make it so it only gives the user 5 letter words or less from the list. My current code for that is:</p>
  
  <pre><code>word_site = "http://www.instructables.com/files/orig/FLU/YE8L/H82UHPR8/FLUYE8LH82UHPR8.txt"
  response = urllib2.urlopen(word_site)
  txt = response.read()
  WORDS = txt.splitlines()
  randomword=(random.choice(WORDS))
  </code></pre>
  
  <p>Currently the code above gets any random word from that word list, I would like it to only get words that have 5 or less letters in them.</p>
  
  <p>Here is all my code below, if it helps you:</p>
  
  <pre><code>import random
  import urllib2
  loop=True
  while loop==True:
      name=raw_input("Hello there! What might your name be? ")
      yesorno=raw_input("Hello " + name + ", would you like to play a friendly game of Guess the Word? Answer either 'yes' or 'no': ")
      if yesorno == "yes":
          loop=False
          print "Ok then, here we go!"
          print "\n"
          print "You have 3 guesses"
          word_site = "http://www.instructables.com/files/orig/FLU/YE8L/H82UHPR8/FLUYE8LH82UHPR8.txt"
          response = urllib2.urlopen(word_site)
          txt = response.read()
          WORDS = txt.splitlines()
          randomword=(random.choice(WORDS))
          lengthrandomword=len(randomword)
          print "I'm thinking of a word with " + str(lengthrandomword) + " letters"
          print "\n"
          if lengthrandomword==2:
              print "_ _"
              print "\n"
          elif  lengthrandomword==3:
              print "_ _ _"
              print "\n"
          elif  lengthrandomword==4:
              print "_ _ _ _"
              print "\n"
          elif  lengthrandomword==5:
              print "_ _ _ _ _"
              print "\n"
          elif  lengthrandomword==6:
              print "_ _ _ _ _ _"
              print "\n"
          elif  lengthrandomword==7:
              print "_ _ _ _ _ _ _"
              print "\n"
          elif  lengthrandomword==8:
              print "_ _ _ _ _ _ _ _"
              print "\n"
          elif  lengthrandomword==9:
              print "_ _ _ _ _ _ _ _ _"
              print "\n"
          elif  lengthrandomword==10:
              print "_ _ _ _ _ _ _ _ _ _"
              print "\n"
          elif  lengthrandomword==11:
              print "_ _ _ _ _ _ _ _ _ _ _"
              print "\n"
          elif  lengthrandomword==12:
              print "_ _ _ _ _ _ _ _ _ _ _ _"
              print "\n"
          elif  lengthrandomword==13:
              print "_ _ _ _ _ _ _ _ _ _ _ _ _"
              print "\n"
          elif  lengthrandomword==14:
              print "_ _ _ _ _ _ _ _ _ _ _ _ _ _"
              print "\n"
          elif  lengthrandomword==15:
              print "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _"
              print "\n"
          else:
              print "I thought of a word and it's reeeaaaaaly long, you would never guess it, so I'm just gonna tell you that my word was " + randomword
          print "\n"
          userguess=raw_input("Try and guess the word: ")
          input = randomword
          output = ""
          for i in input.split():
              output += i[0]
          firstletter=output
          if randomword.endswith("a"):
              lastletter="a"
          elif randomword.endswith("b"):
              lastletter="b"
          elif randomword.endswith("c"):
              lastletter="c"
          elif randomword.endswith("d"):
              lastletter="d"
          elif randomword.endswith("e"):
              lastletter="e"
          elif randomword.endswith("f"):
              lastletter="f"
          elif randomword.endswith("g"):
              lastletter="g"
          elif randomword.endswith("h"):
              lastletter="h"
          elif randomword.endswith("i"):
              lastletter="i"
          elif randomword.endswith("j"):
              lastletter="j"
          elif randomword.endswith("k"):
              lastletter="k"
          elif randomword.endswith("l"):
              lastletter="l"
          elif randomword.endswith("m"):
              lastletter="m"
          elif randomword.endswith("n"):
              lastletter="n"
          elif randomword.endswith("o"):
              lastletter="o"
          elif randomword.endswith("p"):
              lastletter="p"
          elif randomword.endswith("q"):
              lastletter="q"
          elif randomword.endswith("r"):
              lastletter="r"
          elif randomword.endswith("s"):
              lastletter="s"
          elif randomword.endswith("t"):
              lastletter="t"
          elif randomword.endswith("u"):
              lastletter="u"
          elif randomword.endswith("v"):
              lastletter="v"
          elif randomword.endswith("w"):
              lastletter="w"
          elif randomword.endswith("x"):
              lastletter="x"
          elif randomword.endswith("y"):
              lastletter="y"
          elif randomword.endswith("z"):
              lastletter="z"
          else:
              lastletter="I CODED SOMETHING WRONG!"
          if userguess != randomword:
              print "You guessed wrong..."
              print "\n"
              print "I'll give you a hint: the word STARTS with the letter " + firstletter + " and ENDS with the letter " + lastletter
              userguess=raw_input("I'll give you another chance to guess the word: ")
              if userguess != randomword:
                  input = randomword
                  output = ""
                  for i in input.split():
                      output += i[1]
                  secondletter=output
                  print "You guessed wrong..."
                  print "\n"
                  print "I'll give you another hint: the second letter of the word is " + secondletter
                  userguess=raw_input("I'll give you one last chance to guess the word: ")
                  if userguess != randomword:
                      print "You guessed wrong..."
                      print "\n"
                      print "You're out of chances... the word was: " + randomword
                      print "I'm sorry to say this but..."
                      print "YOU LOST!"
                      print "\n"
  
                  elif userguess == randomword:
                      print "You guessed right!"
                      print "YOU WON!"
                      print "\n"
                  else:
                      print "I made a mistake in the code somewhere?!"
          elif userguess == randomword:
              print "You guessed right!"
              print "YOU WON!"
              print "/n"
          else:
              print "I made a mistake in the code somewhere?!"
          mindchange=raw_input("Wanna play again? If you do, just type 'Start'. If you don't then type 'Exit': ")
          if mindchange=="Exit":
              loop=False
          elif mindchange=="Start":
              loop=True
          else:
              print "You didn't type either 'Start' or 'Exit' : remember to include the Capitals!"
              print "\n"
      elif yesorno == "no":
          mindchange=raw_input("Well that's too bad, I was looking forward to beating you... well if you change your mind just type 'Start' but if you still don't want to play just type 'Exit':")
          if mindchange=="Exit":
              loop=False
          elif mindchange=="Start":
              loop=True
          else:
              print "You didn't type either 'no' or 'yes' : remember to not use capitals! "
              print "\n"
  </code></pre>
  
  <p>This is what is returned:</p>
  
  <pre><code>Hello there! What might your name be? Alex
  Hello Alex, would you like to play a friendly game of Guess the Word? Answer either 'yes' or 'no': yes
  Ok then, here we go!
  
  
  You have 3 guesses
  I'm thinking of a word with 14 letters
  
  
  _ _ _ _ _ _ _ _ _ _ _ _ _ _
  
  
  
  
  Try and guess the word: SOMEWORD
  You guessed wrong...
  
  
  I'll give you a hint: the word STARTS with the letter o and ENDS with the letter g
  I'll give you another chance to guess the word: SOMEOTHERWORD
  You guessed wrong...
  
  
  I'll give you another hint: the second letter of the word is v
  I'll give you one last chance to guess the word: SOMEOTHERWORD
  You guessed wrong...
  
  
  You're out of chances... the word was: overregulating
  I'm sorry to say this but...
  YOU LOST!
  
  
  Wanna play again? If you do, just type 'Start'. If you don't then type 'Exit': 
  </code></pre>
  
  <p>If you could also point out where I've been inefficient (which is probably everywhere) as well, that would be appreciated.</p>