这是整个程序。我已经写过问题出现在我的屏幕上。您可以从here拿到正本(第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()
错误的缩进。你知道领先空间在Python中扮演着至关重要的角色吗? – Matthias
你*认为*这是问题发生的地方?你有没有检查错误信息中提到的行号? – Junuxx
第二个代码块包含很多错误,因此很难知道您是否在问题中插入文本时做得不好,或者如果这确实是您拥有的代码。请确保问题中的代码与编辑器中的代码相同。正如Matthias所说;在python中缩进非常重要! – Markus