程序运行前,Python控制台关闭

时间:2019-05-12 16:15:19

标签: python

当我运行程序时,它似乎根本没有运行,只是关闭了控制台。它在IDE中可以正常工作,与它非常相似的程序也可以正常工作。

是的,最后有一个input(),但是在到达该值之前应该有很多东西,代码:

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()

应该像普通的子手游戏一样工作,仍然需要内置第二个播放器功能,但是如果现在不能在控制台中使用它,那以后为什么还要呢?

0 个答案:

没有答案