|
22 | 22 | print("DICTIONARY PREVIEW:", ", ".join(WORDS[:5]) + " ...") |
23 | 23 |
|
24 | 24 | while True: |
25 | | - secret_word = input("\n📝 Enter your secret word: ").lower().strip() |
26 | | - if not secret_word.isalpha(): |
| 25 | + target_word = input("\n📝 Enter your target word: ").lower().strip() |
| 26 | + if not target_word.isalpha(): |
27 | 27 | print("⚠️ Invalid input. Please enter letters only.") |
28 | 28 | continue |
29 | | - if secret_word not in WORDS: |
| 29 | + if target_word not in WORDS: |
30 | 30 | print("⚠️ Word not found in the dictionary.") |
31 | 31 | continue |
32 | 32 | break |
33 | 33 |
|
34 | 34 | print("\n🚀 REVERSE HANGMAN STARTED!!!\n") |
35 | | - pattern = "_" * len(secret_word) |
| 35 | + pattern = "_" * len(target_word) |
36 | 36 | guessed_letters = set() |
37 | 37 | wrong_letters = set() |
38 | 38 | attempts_left = MAX_ATTEMPTS |
|
41 | 41 | while attempts_left > 0 and "_" in pattern: |
42 | 42 | # Get possible words |
43 | 43 | possible_words = [] |
44 | | - if len(secret_word) in WORDS_BY_LENGTH: |
45 | | - for word in WORDS_BY_LENGTH[len(secret_word)]: |
| 44 | + if len(target_word) in WORDS_BY_LENGTH: |
| 45 | + for word in WORDS_BY_LENGTH[len(target_word)]: |
46 | 46 | valid = True |
47 | 47 | for i in range(len(word)): |
48 | 48 | if pattern[i] != "_" and word[i] != pattern[i]: |
|
75 | 75 | guessed_letters.add(guess) |
76 | 76 | print(f"🤖 Computer guesses: {guess.upper()}") |
77 | 77 |
|
78 | | - if guess in secret_word: |
| 78 | + if guess in target_word: |
79 | 79 | print("✅ Correct guess!") |
80 | 80 | # Update pattern |
81 | 81 | pattern_list = list(pattern) |
82 | | - for i in range(len(secret_word)): |
83 | | - if secret_word[i] == guess: |
| 82 | + for i in range(len(target_word)): |
| 83 | + if target_word[i] == guess: |
84 | 84 | pattern_list[i] = guess |
85 | 85 | pattern = "".join(pattern_list) |
86 | 86 | else: |
|
97 | 97 | else: |
98 | 98 | print("💀 Computer failed to guess the word.") |
99 | 99 |
|
100 | | - print(f"💡 Your secret word was: {secret_word.upper()}") |
| 100 | + print(f"💡 Your target word was: {target_word.upper()}") |
101 | 101 |
|
102 | 102 | while True: |
103 | 103 | choice = input("\n🔄 Wanna play again? (y/n): ").lower().strip() |
|
0 commit comments