fix my code, i dunno why it changes the loop, im trynna make a hangman game and it also…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
fix my code, i dunno why it changes the loop, im trynna make a hangman game and it also doesnt show the _'s import random import requests
listo = ["hello", "goodbye", "world"] words = listo end = False
while not end: random_word = random.choice(words) print(f"{random_word} is the word.") the_input = input("What letter do you want to guess? ").lower() display = ["_"] * len(random_word)
codefor position in range(len(random_word)): letter = random_word[position] if letter == the_input: display[position] = letter print(" ".join(display)) # Check if the game should end after updating the display if "_" not in display: print("Congratulations! You've guessed the word!") end = True Assistant
The issue in your code is that you are printing the random word at the beginning of the game, which is not what you want in a hangman game. Also, the game should continue until the user has guessed the word or a certain number of attempts have been made. Here's the corrected code:
Python
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.