我需要帮助在一个python刽子手游戏中打印列表

我需要帮助在一个python刽子手游戏中打印列表,python,Python,在第24行,我一直遇到语法错误,我不知道为什么,我想打印列表,并将列表中的单词添加到hangman游戏中。我知道元组是不可变的,所以我不使用它们。如果有人能帮我纠正这个错误,我将不胜感激 import random import stickman MAX_WRONG = len(stickman.HANGMAN) - 1 MAX_TRYINGS = 7 WORDS = { 'forest':('ANT', 'BABOON', 'BADGER', 'BAT', 'BEAR'),

在第24行,我一直遇到语法错误,我不知道为什么,我想打印列表,并将列表中的单词添加到hangman游戏中。我知道元组是不可变的,所以我不使用它们。如果有人能帮我纠正这个错误,我将不胜感激

import random
import stickman


MAX_WRONG = len(stickman.HANGMAN) - 1
MAX_TRYINGS = 7


WORDS = {
    'forest':('ANT', 'BABOON', 'BADGER', 'BAT', 'BEAR'),
    'desert':('CAMEL', 'COYOTE', 'DONKEY', 'LIZARD', 'HAWK'),
    'swamp':('FROG', 'PYTHON', 'DUCK', 'FISH', 'CROCODILE'),
    'other':('GOAT', 'GOOSE', 'MOLE', 'MOUSE', 'MONKEY')
    }


EXPLANATIONS = (
    ('There once was an animal that lived in the wild it was an', print['forest'],
     'there once was an animal that lived in a desert and it was an',print['desert'],
     'there once was an animal that lived in the swamp and it was an',print['swamp'],
     'there once was an animal that lived all around the world and it was an',print['other'])


HEADER = ('-', 'Hangman Game', 'by Mohammad AlMutairi', '-', '')

INSTRUCTION = ('A certain word has been jumbled,',
               'you are to guess the word that is jumbled', '',
               'In this game you must guess a word by a number ',
               'of finite guesses before being hanged.', '',
               'Good luck!', '')

#menu that explains the objective of the game and is for aesthetic appeal 
for line in HEADER:
    if line:
        print('{:-^60}'.format(line))
    else:
        print('\n')
#asks the user for input on their name and explains the objective of the game
name = input('Hello there! What is your name? ')
print('Welcome {}, to my python hangman game!'.format(name.capitalize()))
for line in INSTRUCTION:
    if line:
        print('{:^60}'.format(line))
    else:
        print('\n')

#menu before starting the game telling the user what to do.
print('Menu\n')
while True:
    for menu_number, group in enumerate(WORDS):
        print('{:2d} - {} animals'.format(menu_number + 1, group[0].capitalize()))
    print(' 0 - Exit')

    #Gets input from the user by what number they have chosen, than gives them hints
    try:
        selection = int(input('Your selection: '))
    except ValueError:
        print('Please enter a number, not a sign!')
        continue
    if selection == 0:
        print('Bye!\n')
        exit()
    elif 0 < selection <= len(WORDS):
        selection -= 1
        break
    print('That is not one of your choices.')

print(EXPLANATIONS[selection].format(random.choice(WORDS[selection][1])))
word = random.choice(WORDS[selection - 1][1])

MAX_WRONG = len(stickman.HANGMAN) - 1

WORDS=['forest','desert','swamp','other']

# 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(stickman.HANGMAN[wrong])
    print("\nYou've used the following letters:\n", used)
    print("\nSo far, the word is:\n", so_far)

    guess = input("\n\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!")
        print("Good job!",name.capitalize(),".")
    # 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(stickman.HANGMAN[wrong])
    print("\nSorry",name.capitalize(),"you have been hanged.")
else:
    print("\nYou guessed it!")


print("\nThe word was", word)
print('''@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@'        .@@@@@@@@+      #@@@@@+      @@@@       @@@            '@@@@@@@@@@@@.       ,@@@@      @@@@@      @.            @@@           ,@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@#` `         #@@@@@@        @@@@@+      +@@@       @@@            '@@@@@@@@@@#           @@@;     @@@@#`   `+@`            @@@             @@@@@@@@@@@@@@@@
@@@@@@@@@@@#,            ,@@@@@@        @@@@@+       @#@       @@@            '@@@@@@@@@@             #@@     '@@@;     @@.            @@@             '@@@@@@@@@@@@@@@
@@@@@@@@@@@@      .`      @@@@@+        #@@@@+       @@`       @@@            '@@@@@@@@@`      +      ,@@      #@@     .@@.            @@@              @@@@@@@@@@@@@@@
@@@@@@@@@@@.     #@@;    #@@@@@          @@@@+       #@        @@@     @@@@@@@@@@@@@@@@@     ,@@@      @@'`    @@@`    #@@.    `@@@@@@@@@@     @@@`     @@@@@@@@@@@@@@@
@@@@@@@@@@@     `@@@@@@@@@@@@@@          @@@@+       `@        @@@            @@@@@@@@@+    `@@@@@     @@@     @@#     @@@.            @@@     @@@      @@@@@@@@@@@@@@@
@@@@@@@@@@@     ;@@     ` #@@@+    ``    #@@@+        ;   `    @@@            @@@@@@@@@+     @@@@#     @@@.     @     :@@@.            @@@        `    #@@@@@@@@@@@@@@@
@@@@@@@@@@@     @@@       #@@@     ';     @@@+            #    @@@            @@@@@@@@@+     @@@@@     @@@@     @     @@@@.            @@@            :@@@@@@@@@@@@@@@@
@@@@@@@@@@@     '@@       #@@@     @@     @@@+    .       #    @@@            @@@@@@@@@+     @@@@@     @@@@     @     @@@@.            #@@           @@@@@@@@@@@@@@@@@@
@@@@@@@@@@@     `@@       #@@:      `     ;@@+    @      `#    @@@     @@@@@@@#@@@@@@@@+     @@@@@     @@@@:         ;@@@@.    `@@@@@@@@@@     :`     @@@@@@@@@@@@@@@@@
@@@@@@@@@@@`     @@@@@    #@@              @@+    @      '+    @@@     @@@@@@@@@@@@@@@@@     '@@@`     @@@@@         @@@@@.    `@@@@@@@@@@     #:`    .@@@@@@@@@@@@@@@@
@@@@@@@@@@@@      ;#,     #@#              #@+    @`     @#    @@@     ;;;;;;;:@@@@@@@@@      :@,`    .@@@@#`       .@@@@@.    `;;;;;;;#@@     @@     `@@@@@@@@@@@@@@@@
@@@@@@@@@@@@`             #@`              .@+    @;     @+    @@@             @@@@@@@@@#`            @@@@@@#       #@@@@@.            +@@     @@+      @@@@@@@@@@@@@@@
@@@@@@@@@@@#@            `@@     `#@@@`     @+    @@    .@+    @@@             @@@@@@@@@@;`          #@@@@@@@       @@@@@@.            +@@     @@#      @@@@@@@@@@@@@@@
@@@@@@@@@@@@@@,`        #@@@`    ;@@@@:     @+  ` @@    @@#    @@@             #@@@@@@@@@@#       ` #@@@@@@@@`     ,@@@@@@.            +@@     @@@#      @@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@++++++@@@@@@@@@@##@@@@#@@@@@@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@@@@@@#@@@@@@@@@@@@@+++++@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
''')
随机导入
进口刺客
MAX_错=len(stickman.HANGMAN)-1
最大尝试数=7
单词={
‘森林’:(‘蚂蚁’、‘狒狒’、‘獾’、‘蝙蝠’、‘熊’),
‘沙漠’:(‘骆驼’、‘土狼’、‘驴’、‘蜥蜴’、‘鹰’),
‘沼泽’:(‘青蛙’、‘蟒蛇’、‘鸭子’、‘鱼’、‘鳄鱼’),
‘其他’:(‘山羊’、‘鹅’、‘鼹鼠’、‘老鼠’、‘猴子’)
}
解释=(
(“曾经有一种动物生活在野外,它是一种动物”,印刷品[“森林],
“曾经有一种动物生活在沙漠里,它是一种,”,print[“沙漠”],
“曾经有一种动物生活在沼泽里,它是一种”印刷品[“沼泽”],
“曾经有一种动物生活在世界各地,它是一种”印刷品[“其他”])
页眉=(“-”、“刽子手游戏”、“穆罕默德·阿尔穆塔伊里创作的”、“-”、”)
指令=(“某个单词已被混淆,”,
“你得猜一猜这个词,这个词很混乱”,
“在这个游戏中,你必须用数字猜一个单词”,
“被绞死前的有限猜测”,
“祝你好运!”
#菜单说明了游戏的目的,并具有审美吸引力
对于标题中的行:
如果行:
打印(“{:-^60}”。格式(行))
其他:
打印(“\n”)
#要求用户输入他们的名字,并解释游戏的目标
name=input('你好!你叫什么名字?')
print('Welcome{},来到我的python刽子手游戏!'.format(name.capitalize())
对于行输入指令:
如果行:
打印(“{:^60}”。格式(行))
其他:
打印(“\n”)
#在开始游戏之前,菜单会告诉用户该做什么。
打印('菜单\n')
尽管如此:
对于菜单号,在枚举中分组(单词):
打印({:2d}-{}动物)。格式(菜单编号+1,组[0]。大写()
打印('0-退出')
#按用户选择的数字从用户处获取输入,然后向用户提供提示
尝试:
selection=int(输入('您的选择:'))
除值错误外:
打印('请输入数字,而不是符号!')
持续
如果选择==0:
打印('再见!\n')
退出()

elif 0
EXPLANATIONS = (
    ('There once was an animal that lived in the wild it was an', print['forest'],
     'there once was an animal that lived in a desert and it was an',print['desert'],
     'there once was an animal that lived in the swamp and it was an',print['swamp'],
     'there once was an animal that lived all around the world and it was an',print['other'])
关上它

EXPLANATIONS = (
    ('There once was an animal that lived in the wild it was an', print['forest'],
     'there once was an animal that lived in a desert and it was an',print['desert'],
     'there once was an animal that lived in the swamp and it was an',print['swamp'],
     'there once was an animal that lived all around the world and it was an',print['other']
    )
)
这不是有效的python代码。
print['…']
?这应该做什么?如果编写正确,您希望得到什么

>>> example = (print('forest'), print('desert'), print('swamp'))
forest
desert
swamp
>>> print(example)
(None, None, None)

你能给我们看一下异常和回溯吗?我猜那是python3,因为否则你会在第18行出现语法错误,因为
打印
…这仍然是错误的,并且会导致
属性错误
打印
一般来说似乎放错地方了,你肯定不想打印一些东西在这一点上。一般来说,您对该语言的掌握似乎很不完整,我建议您在继续之前阅读一些教程和示例。@user305206我猜其中大部分都是基本错误。搜索一下。您会找到答案。虽然您认为这是无意义的,但在python 3中它在语法上是有效的(但运行时将导致
属性错误
,除非
打印
已被修改或重新分配)。此外,我已从您的帖子中删除签名-无需签名,因为您的姓名和图片已包含在每个问题或答案中,并且正在这样做。
>>> example = (print('forest'), print('desert'), print('swamp'))
forest
desert
swamp
>>> print(example)
(None, None, None)