Untitled
import random def choose_secret_world(): worlds = ["yesus"] return random.choice(worlds) def display_hint(secret_world, correct_guesses): hint = "" for letter in secret_world: if letter in correct_guesses: hint += letter + " " else: hint += "_ " return hint.strip() def world_guessing_game(): secret_world = choose_secret_world() correct_guesses = set() attempts = 0 print("Welkom!") print(f"Your hint is: {display_hint(secret_world, correct_guesses)}") while True: guess = input("What is your guess? ").lower() if len(guess) != len(secret_world): print("Sory, the guess must have the same number of letters as the secret world.") continue attempts += 1 if guess == secret_world: print(f"Congratulations! You guessed it!\nIt took you {attempts} guesses.") break else: correct_guesses.update(set(guess)) print(f"Your hint is: {display_hint(secret_world, correct_guesses)}") if __name__ == "__main__": world_guessing_game()
Leave a Comment