刽子手游戏Python错误

时间:2014-08-26 07:16:11

标签: python

我试图在python中创建刽子手游戏,但是出现了以下错误 当我试图运行该文件。

guess =输入(" \ n输入您的猜测:")

文件字符串",第1行,在模块

如果您知道修复此错误的解决方案,请与我们联系

#!/usr/bin/python
# imports
import random

# constants
HANGMAN = (
"""
------
|    |
|
|
|
|
|
|
|
----------
""",
"""
------
|    |
|    O
|
|
|
|
|
|
----------
""",
"""
------
|    |
|    O
|   -+-
|
|  
|  
|  
|  
----------
""",
"""
------
|    |
|    O
|  /-+-
|  
|  
|  
|  
|  
----------
""",
"""
------
|    |
|    O
|  /-+-/
|  
|  
|  
|  
|  
----------
""",
"""
------
|    |
|    O
|  /-+-/
|    |
|  
|  
|  
|  
----------
""",
"""
------
|    |
|    O
|  /-+-/
|    |
|    |
|   |
|   |
|  
----------
""",
"""
------
|    |
|    O
|  /-+-/
|    |
|    |
|   | |
|   | |
|  
----------
""")

MAX_WRONG = len(HANGMAN) - 1
WORDS = ("OVERUSED", "CLAM", "GUAM", "TAFFETA", "PYTHON", "HARDWICKE", "BRADLEY", "SHEFFIELD")

# initialize variables
word = random.choice(WORDS)   # the word to be guessed
so_far = "-" * len(word)      # one dash for each letter in word to be guessed
wrong = 0                     # number of wrong guesses player has made
used = []                     # letters already guessed


print("Welcome to Hangman.  Good luck!")

while wrong < MAX_WRONG and so_far != word:
    print(HANGMAN[wrong])
    print("\nYou've used the following letters:\n", used)
    print("\nSo far, the word is:\n", so_far)

    print("\nOnly use one letter values, more than one letter at a time does not work at this time")
    guess = input("\nEnter your guess: ")
    guess = guess.upper()

    while guess in used:
        print("You've already guessed the letter", guess)
        guess = input("Enter your guess: ")
        guess = guess.upper()

    used.append(guess)

    if guess in word:
        print("\nYes!", guess, "is in the word!")

        # create a new so_far to include guess
        new = ""
        for i in range(len(word)):
            if guess == word[i]:
                new += guess
            else:
                new += so_far[i]              
        so_far = new

    else:
        print("\nSorry,", guess, "isn't in the word.")
        wrong += 1

if wrong == MAX_WRONG:
    print(HANGMAN[wrong])
    print("\nYou've been hanged!")
else:
    print("\nYou guessed it!")

print("\nThe word was", word)

input("\n\nPress the enter key to exit.")

1 个答案:

答案 0 :(得分:1)

  guess = raw_input("\nEnter your guess: ")

它应该是raw_input,而不是输入。