import random
def get_password_and_hint():
"""Return a random password with its corresponding hint."""
passwords = {
"Alice": "Name",
"Paris": "Place",
"Eiffel": "Thing",
"Python": "Programming Language",
"Giraffe": "Animal",
"Mount Everest": "Place",
"Chocolate": "Food",
"Titanic": "Historical Event"
}
password, hint = random.choice(list(passwords.items()))
return password, hint
def display_current_state(password, guessed_letters):
"""Display the current state of the guessed password."""
return ' '.join(letter if letter in guessed_letters else '_' for letter in password)
def main():
password, hint = get_password_and_hint()
guessed_letters = set()
attempts = 6 # Number of incorrect guesses allowed
print("Welcome to the Hangman Password Guessing Game!")
print(f"Hint: {hint}")
while attempts > 0:
print(display_current_state(password, guessed_letters))
guess = input("Guess a letter: ").strip()
if len(guess) != 1 or not guess.isalpha():
print("Please enter a single letter.")
continue
if guess in guessed_letters:
print("You've already guessed that letter.")
continue
guessed_letters.add(guess)
if guess in password:
print("Good guess!")
else:
attempts -= 1
print(f"Incorrect guess. You have {attempts} attempts left.")
if all(letter in guessed_letters for letter in password):
print(f"Congratulations! You've guessed the password '{password}'.")
break
if attempts == 0:
print(f"Game over! The password was '{password}'.")
if __name__ == "__main__":
main()