これがプログラム全体です。画面のどこで問題が発生するかを書きました。元のコピーはここから入手できます(第 6 章、Dragon Realm)。
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()