这是整个程序。我已经在我的屏幕上写了问题发生的位置。你可以从这里获得原版(第 6 章,龙界)
import random
import time
def displayIntro():
print('You are in a land full of dragons. In front of you,')
print('you see two caves. In one cave, the dragon is friendly')
print('and will share his treasure with you. The goblin')
print('is greedy and wants to loot you on sight.')
print()
def chooseCave():
cave = ''
while cave != '1' and cave != '2':
print('Which cave will you go into? (1 or 2)')
cave = input()
return cave
def checkCave(chosenCave):
print('You approach the cave...')
time.sleep(2)
print('It is dark and spooky...')
time.sleep(2)
print('The goblin sees you and tells you too hand over your stuff')
time.sleep(2)
print("oh! I forgot you are an apprentice looking Merlin you can use ur magic on him")
time.sleep(1)
print("You can choose betweeen, fire, water, air or earth")
print()
time.sleep(2)
friendlyCave = random.randint(1, 2)
if chosenCave == str(friendlyCave):
print('Gives you his treasure!')
else:
print('Takes your stuff and run')
def spell(magic):
这是关于我认为问题发生的地方。
if magic == 'air' or magic == 'fire' or magic == 'water' or magic == 'earth' #This is where the problem occurs I think it is because of some prior codes
def choosespell(maguc)#choose between spells
if magic == 'air':
print('you blew the goblin away')
elif magic == 'fire':
print('you burned the goblin to death')
elif magic == 'water':
print('the goblin drowned to death')
elif magic == 'earth':
print('The veins chocked him to death')
magic = input()
playAgain = 'yes'
while playAgain == 'yes' or playAgain == 'y':
displayIntro()
caveNumber = chooseCave()
checkCave(caveNumber)
print('Do you want to play again? (yes or no)')
playAgain = input()