When I run my program it seems like it doesn't even run at all, and just closes the console. It works just fine in the IDE, and a program very similar to it also works just fine.

Yes there is an input() at the very end, but there should be a lot before it reaches that, code:

import random
import os

words_list=[]

def player1_word():
    words=open("hangman_words.txt","a")
    p1_word=input("Player1, enter a word: ")
    words.write(p1_word.lower()+"\n")
    words.close()

def player2_word():
    words=open("hangman_words.txt","a")
    p2_word=input("Player2, enter a word: ")
    words.write(p2_word.lower()+"\n")
    words.close()

def game_word():
    words=open("hangman_words.txt","r")
    for line in words:
        words_list.append(line[0:len(line)-1])
    word=random.choice(words_list)
    words.close()
    return word

player1_word()
player2_word()
word=game_word()

guesses=5
word_length=[]
entered_letters=[]
incorrect_letters=[]
for i in range(len(word)):
    word_length.append('_')
print (word_length)
letter_remaining=len(word)

while guesses!=0:
    error=len(word)
    guess_word=input("Enter a letter: ")
    for i in range(len(word)):
        if word_length[i]==guess_word:
            print("Enter a letter that has not been entered before")
            break
        elif word[i]==guess_word:
            word_length[i]=word[i]
            letter_remaining-=1
        elif word[i]!=guess_word:
            error-=1
    if error==0:
        guesses-=1
    print (word_length)
    print ("Remaining Guesses:",guesses)
    if letter_remaining==0:
        print("Congrats! You got the word '", word, "' with" , guesses, "guesses remaining")
        break
    elif guesses==0:
        print("You lose, the word was '", word, "'")
        break
input()

should work like a normal hangman game, still need a second player function to build into it, but if it doesn't work in the console now, why should it later?

0 Answers