I am trying to figure out why the Python code returns Incorrect when I type in the correct second letter.
For example, if the word is Fox
, then the F
would be correct, and the O
would be incorrect. I'm guessing it has to do with the last bit
import random
# Welcome section
# Create function welcome
# Print "Welcome to hangman, new line, instructions for game"
# main loop function
def main():
score = 0
word = get_word('words.txt')
# save get_word() in a variable "word"
print(len(word) - 1) # Tell user length of word
print(word)
print("Only add one char
") # Also tell user rules (only guess one character)
# Game loop
while (score < 6):
# Print "Your score is ” and then the score variable
# Saves guess into “guess” variable
guess = input("Guess: ")
# If user types full word
if len(guess) > 1:
print("That is incorrect, don't type full words")
# bad (they wrote a full word instead of a character)
while (len(guess) > 1):
guess = input(“Guess again: “)
# If user types one character
if len(guess) == 1:
if guess in word:
print("Congratulations you got the letter right!")
else:
score += 1
print("Incorrect, keep trying!")
Would I need an elif
in this situation?
question from:
https://stackoverflow.com/questions/65929124/hang-man-only-returns 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…