检查此列表中的拼图文字游戏

时间:2015-03-16 17:58:54

标签: python

重点是创造一个文字游戏,争夺这个词并解决它。我需要指导,看看我是否进行了洗牌,猜测(计数,如果正确,如果错误),如果它重复正确,请:

def main():

    print("Welcome to my game, solve the puzzle.")

    print("lets play")


    wordlist= open("wordlist.txt", "r")

    import random

    def randomWord(wordlist):
        wIndex = random.randint(0, len(wordlist)- 1)
        return wordlist[wIndex]
        print("Here is the word: ")


    def displayGame(wrong, right):
        print("Wrong Guesses:", end=" ")
        for letter in wrong:
            print(letter, end=" ")
        print()


        blanks = '-'*len(secret)

    for i in range(0, len(secret) - 1):
        if secret[1] in right:
            blanks = blanks[:i] + secret[i] + blanks[i+1:]

    for letter in blanks:
        print(letter, end=" ")
        print()

    def getguess(guessed):
        while True:
            guess = input()
            guess = guess.lower()
            if len(guess) != 1:
                print("Enter you letter.")
            elif guess in guessed:
                print("Try again, you have already use that letter.")
            elif guess not in "abcdefghijklmnopqrstuvwxyz":
                print("please enter a letter")
            else:
                return guess

    def playAgain():
        print("Would you like to play again? (yes or no)", end=" ")
        while True:
            keepGoing = input()
            if keepGoing == "yes":
                return True
            elif keepGoing == "no":
                return False
            else:
                print("yes or no please.")

1 个答案:

答案 0 :(得分:0)

这里出现了很多问题,我花了很多时间来查看代码并注意特定行的错误。您可以找到该列表here,但它并没有真正回答您的问题,因此我不会在此处粘贴整个分析。

关于为什么在运行代码时没有任何反应的问题的答案是,您永远不会调用main,只能定义它。

def my_main():
    print("Do a bunch of stuff here!")

# never gets called

运行此代码时没有任何反应。你必须这样做:

def my_main():
    print("Do a bunch of stuff here!")

main()

让它运行。

正如我上面提到的:你编写的代码不会做你想要做的事情。然而,这个问题与根本没有做任何事情是分开的。如果你需要一些帮助来实现我在上面的链接中建议的更改,请随意提出另一个关于SPECIFIC问题的问题你是在尝试改变之后。