import random
import sys

print "# Play the Matching Pennies game."
print "# Type H for HEADS, T for TAILS, Q to quit."
while 1==1:
 current = ""
 while current == "":
  inn = raw_input('? ')

  if inn != "":
   if inn[0] == "Q":
    sys.exit()
   if inn[0] == "H":
    current = "HEADS"
   if inn[0] == "T":
    current = "TAILS"
 rnd_throw = "TAILS"
 rnd = random.random()
 if rnd>0.5:
  rnd_throw = "HEADS"
 match = rnd_throw == current
 match_string = "Mismatch!";
 if match:
  match_string = "Match!";
 print rnd_throw+" - Test - You: "+current+". Me: "+rnd_throw+". "+match_string
