【发布时间】:2017-11-04 00:19:35
【问题描述】:
我是编码初学者,目前正在制作 rpg。当我运行代码时,它给了我上述错误。给我错误的部分是print("You are on " + floors[currentRoom] + ". You find " + floorsFeature[currentRoom])。我的猜测是 floors、floorsFeature 和 currentRooms 一定有问题。因为我是初学者,所以我不确定错误是什么意思。有人可以简单解释一下吗?
print("You are finally a Pokemon trainer! Today, you have gotten your very first Pokemon, a Bulbasaur!")
name = input("What will you name your Bulbasaur? ")
print("Unfortunately, " + name + " doesn't seem to obey or like you...")
print("You try to be friendly to " + name + ", but it just won't listen...")
print("As " + name + " was busy ignoring you, something seems to catch its attention and it runs off!")
print("You chase after " + name + ", but it's too fast! You see it running into an abandoned Pokeball Factory.")
print("You must explore the abandoned Pokeball Factory and find " + name + " before something happens to it!")
print()
print("You may input 'help' to display the commands.")
print()
gamePlay = True
floors = [['floor 1 room 1', 'floor 1 room 2', 'floor 1 room 3', 'floor 1 room 4'],['floor 2 room 1', 'floor 2 room 2', 'floor 2 room 3', 'floor 2 room 4', 'floor 2 room 5'],['floor 3 room 1,' 'floor 3 room 2', 'floor 3 room 3'],['floor 4 room 1', 'floor 4 room 2']]
floorsFeature = [['nothing here.', 'nothing here.', 'stairs going up.', 'a Squirtle.'],['stairs going up and a pokeball.', 'a Charmander.', 'a FIRE!!!', 'stairs going down.', 'a pokeball.'],['stairs going down.', 'a door covered in vines.', '2 pokeballs!'],['your Bulbasaur!!!', 'an Eevee with a key tied around its neck.']]
currentRoom = [0][1]
pokemonGot = []
count = 0
bagItems = []
countItems = 0
while gamePlay == True:
print("You are on " + floors[currentRoom] + ". You find " + floorsFeature[currentRoom])
move = input("What would you like to do? ")
while foo(move) == False:
move = input("There's a time and place for everything, but not now! What would you like to do? ")
if move.lower() == 'left':
if currentRoom > 0:
currentRoom = currentRoom - 1
print("Moved to " + floors[currentRoom] + ".")
else:
print("*Bumping noise* Looks like you can't go that way...")
elif move.lower() == 'right':
if currentRoom < len(floors) - 1:
currentRoom = currentRoom + 1
print("Moved to " + floors[currentRoom] + ".")
else:
print("*Bumping noise* Looks like you can't go that way...")
elif move.lower() == 'help':
print("Input 'right' to move right. Input 'left' to move left. Input 'pokemon' to see what Pokemon are on your team. Input 'bag' to see the items you are carrying. Input 'help' to see the commands again.")
elif move.lower() == 'pokemon':
if count == 0:
print("There are no Pokemon on your team.")
else:
print("The Pokemon on your team are: " + ", ".join(pokemonGot) + ".")
elif move.lower() == 'bag':
if countItems == 0:
print("There are no items in your bag.")
else:
print("The items in your bag are: " + ", ".join(bagItems) + ".")
print()
【问题讨论】:
-
currentRoom = [0][1] 这段代码正确吗?只是为了仔细检查
-
'floor 3 room 1,' 'floor 3 room 2', ...出现另一个拼写错误,逗号应该不在引号内。
标签: python python-3.x