【发布时间】:2019-01-09 17:55:22
【问题描述】:
我正在制作一个基于文本的冒险游戏,并尝试根据玩家在其库存中拥有一个密钥来将项目添加到目录中。
我已经尝试了所有我能找到的解决方案,但都没有奏效。我想这可能是因为我的语法与其他词典不同。
if 'key' in inventory:
print('Well done for killing all monsters on the first floor! You can
now
travel upstairs from the hall')
'Hall' ['upstairs'] = 'Landing'
'Hall' : {
'south' : 'Kitchen',
'east' : 'Dining Room',
'north' : 'Library',
'west' : 'Game Room',
},
请告诉我另一种方式
'Hall' ['upstairs'] = 'Landing'
无需更改所有目录,因为我还有许多其他房间。
【问题讨论】:
-
什么是'Hall'的类型?
-
Um
'Hall' ['upstairs'] = 'Landing'正在尝试将基于索引的赋值用于 字符串,'Hall'与另一个字符串作为键。 -
@junapa.arrivillaga:这只是之前不起作用的解决方案之一。
标签: python python-3.x dictionary if-statement game-development