我正在按照教程创建文本冒险,我现在正在创建部分,但还没有完成,但有些东西我就是不明白。所以,我正在为这些部分创建一个数组。该数组包括描述和名称。现在该部分的名称有一个降低它的代码,用 - 替换空格。它会删除句号和撇号。然后将其放入一个名为 sec 的数组中。这是我不明白的部分:
sec = {}
for indexed in enumerate(sections):
index = indexed[0]
long_name = indexed[1][1]
short_name = ''
for C in long_name:
if C == ' /':
short_name += '-'
elif not C == ".'":
short_name += C.lower()
sec[short_name] = index
这是我的全部代码:
import time
import random
sections = [
(
"""You are in front of your friend's house. Your friend's house is
(n)orth and the driveway is south. There is a mailbox next to you.""",
"Front Of Friend's House"), #0
(
"""You are in your friend's house. Northwest is the stairs, the
kitchen is up north, the door is south. Your friend is upstairs.""",
"Friend's house"), #1
(
"""You are upstairs, the bathroom is up north, your friend's bedroom
is west. The stair down is south.""",
"Friend's house upstairs"), #2
]
sec = {}
for indexed in enumerate(sections):
index = indexed[0]
long_name = indexed[1][1]
short_name = ''
for C in long_name:
if C == ' /':
short_name += '-'
elif not C == ".'":
short_name += C.lower()
sec[short_name] = index
有人可以向我解释我不明白的部分吗,我不喜欢在不知道自己在做什么的情况下写东西。我也不知道for是什么意思。以及如何在没有定义或其他东西的情况下使用 C。如果你能向我解释这一点,那就太好了!