Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.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
Python 我得到一个错误,说开始没有定义。我怎么修理它?_Python_Function - Fatal编程技术网

Python 我得到一个错误,说开始没有定义。我怎么修理它?

Python 我得到一个错误,说开始没有定义。我怎么修理它?,python,function,Python,Function,我正在尝试创建一个刽子手游戏 Python一直告诉我,get\u word没有定义,但我不确定它为什么这么说 get_word(): dictionary = ["number","one","hyper","active","knuckle","head","ninja"] import random process_guess(): while keep_playing: dictionary=["number","one","hyper","act

我正在尝试创建一个刽子手游戏

Python一直告诉我,
get\u word
没有定义,但我不确定它为什么这么说

get_word():
    dictionary = ["number","one","hyper","active","knuckle","head","ninja"]
    import random

process_guess():
    while keep_playing:
        dictionary=["number","one","hyper","active","knuckle","head","ninja"]
        word=choice(dictionary)
        word_len=len(word)
        guesses=word_len * ['_']
        max_incorrect=7
        alphabet="abcdefghijklmnopqrstuvxyz"
        letters_tried=""
        number_guesses=0
        letters_correct=0
        incorrect_guesses=0
        print_game_rules(max_incorrect,word_len)
        while (incorrect_guesses != max_incorrect) and (letters_correct != word_len):
            clues()
            letter=get_letter()
            if len(letter)==1 and letter.isalpha():
                if letters_tried.find(letter) != -1:
                    print ("letter has already been used", letter)
                else:
                    letters_tried = letters_tried + letter
                    first_index=word.find(letter)
                    if  first_index == -1:
                        incorrect_guesses= incorrect_guesses +1
                        print ("The",letter,"is not the unknown word.")
                    else:
                        print("The",letter,"is in the unknown word.")
                        letters_correct=letters_correct+1
                        for i in range(word_len):
                            if letter == word[i]:
                                guesses[i] = letter
            else:
                print ("Please guess a single letter in the alphabet.")
                print("victory:",no guesses ')


play():
    1 = yes
    0 = no
    print(("play again? (1-yes, 0-no")):

print("get the current guess letter:", current)





main()

在Python中,使用
def
关键字定义新函数。我们也要这样做:

def get_word():

在Python中,新函数是使用
def
关键字定义的。我们也要这样做:

def get_word():

在其他任何地方都可以定义函数。

因此,您更改了问题中的代码以添加该函数。那不是你的问题吗?不,是的,那是问题的一部分。我只是不知道为什么它一直这么说。但问题更多的是代码作为一个整体是否会运行。嗯,有很多潜在的原因导致代码可能无法运行。(1)
main()
未定义;(2)
1=yes
没有意义;(3) 缩进看起来乱七八糟;(4)
选择
(可能来自
随机
?)不合格;(5)
no uz's猜测“
是一个语法错误。所以我会先把它们弄清楚。所以,你修改了你问题中的代码来添加它。那不是你的问题吗?不,是的,那是问题的一部分。我只是不知道为什么它一直这么说。但问题更多的是代码作为一个整体是否会运行。嗯,有很多潜在的原因导致代码可能无法运行。(1)
main()
未定义;(2)
1=yes
没有意义;(3) 缩进看起来乱七八糟;(4)
选择
(可能来自
随机
?)不合格;(5)
no uz's猜测“
是一个语法错误。所以我会先把它们弄清楚。