import re# Get answer.
answer = "what's up doc?"

answer = answer. upper()

answer_guessed = {}



# determine wheather characters in the amswer needs to be guessed 
for answer_character in answer:
  if re.search ("^{A-Z}$", answer_character):
    answer_guessed .append(false)
  else:
    answer_guessed.append(true)
    
# game logic.
guessed_letters = []
TOTAL_NUM_OF_INCORRECT_GUESSES_ALLOWED = 5
num_of_incorrect_guesses = 0

while num_of_incorrect_guesses < TOTAL_NUM_OF_INCORRECT_GUESSED_ALLOWED and FALSE in answer_guessed:
  print("...............")
  print("letters guessed: ", end = "")

  for current_guessed_letter in guessed_letters:
    print(f"{current_guessed_letter} ", end = "")

  print()

  print(f"number of incorrect guesses remaining: {TOTAL_NUM_OF_GUESSES_ALLOWED - NUM_ OF_ GUESSES}")

  print()
  for answer_index in range(len(answer)):
   if answer_guessed[answer_index]:
     print(answer[answer_index], end ="")
   else:
     print("_", end ="")
     

  print()

  letter = input("enter a letter ")

  letter = letter.upper()

  if letter not in guessed_letters and len(letter)==1 and re.search ("^{A-Z}$", letter):
    # process the letter in the puzzle 
    guessed_letters_insert_index = 0

    for current_guessed_letter in guessed_letters:
      if letter < current_guessed_letter:
        break

      guessed_letters_insert_index+=1

    if letter in answer:
      #letter is in the puzzle 
      for answer_index in range(len(answer)):
        if letter == answer[answer_index]:
          answer_guessed[answer_index] = True 
    else:
      # letter is not in the puzzle 
      num_of_incorrect_guesses += 1

# post-game summary.
if num_of_incorrect_guesses< TOTAL_NUM_OF_INCORRECT_GUESSES_ALLOWED:
  print("congratulations, you solved the puzzle!")
else:
  print("sorry,you ran out of guesses.")

print(f"{answer} is the answer to the puzzle.")