Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
I';我正在用Python制作一个关于刽子手的游戏,我不';我不知道我的代码出了什么问题_Python - Fatal编程技术网

I';我正在用Python制作一个关于刽子手的游戏,我不';我不知道我的代码出了什么问题

I';我正在用Python制作一个关于刽子手的游戏,我不';我不知道我的代码出了什么问题,python,Python,我正在用python制作一个关于刽子手的游戏,我不确定我的代码哪里出了问题。我希望它打印已经猜到的字母,然后在单词的指定位置显示正确猜到的字母。例如A--M-L 这还没有完成,但我想在继续之前解决它,所以任何帮助都是感激的 代码如下: # Hang Man import random import string from words import word_choices # Prints a welcome message to the user print("")

我正在用python制作一个关于刽子手的游戏,我不确定我的代码哪里出了问题。我希望它打印已经猜到的字母,然后在单词的指定位置显示正确猜到的字母。例如A--M-L

这还没有完成,但我想在继续之前解决它,所以任何帮助都是感激的

代码如下:

# Hang Man

import random
import string
from words import word_choices

# Prints a welcome message to the user

print("")
print("Welcome to Hang Man!")

# Creates a dictionary of all the possible words the program can pick from

Word_Choices = [word_choices]

# Randomly chooses a word from the dictionary

HangMan_Word = (random.choice(word_choices))

# Counts how many letters there are in the word and tells the user

HangMan_Word_Letters = len(HangMan_Word)
print("")
print("The word has", HangMan_Word_Letters, "letters")
print("")

# Creates an alphabet of letters

alphabet = string.ascii_uppercase

used_letters = set()  # All of the used letters go here

while len(HangMan_Word) > 0:
    print("You have used these letters: ", " ".join(used_letters))  # prints the letters that have been used

    # Where the characters are that they haven't guessed

    word_list = [guess if guess in used_letters else "-" for guess in HangMan_Word]
    print("Current word: ", " ".join(word_list))

    # Asks the user for a guess

    print("")
    guess = input("Make a guess!").upper()

    def subtract():

        if guess in alphabet - used_letters:  # Validates the guess
            used_letters.add(guess)
            if guess in HangMan_Word:
                HangMan_Word.remove(guess)

        elif guess in used_letters:
            print("This letter has been guessed already")

        else:
            print("Invalid character")

你到底面临什么样的问题。。!