-4

这是整个程序。我已经在我的屏幕上写了问题发生的位置。你可以从这里获得原版(第 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()
4

2 回答 2

4

您似乎没有掌握 Python 语法和语义的基础知识。我建议您不要先尝试阅读代码,而不要首先至少了解一些语言语法的基本知识,因为您会感到困惑。

老实说,请先尝试阅读python书籍。两个很棒的(而且是免费的)Dive into PythonLearn Python the Hard way

于 2012-12-04T12:38:35.567 回答
2

在函数定义选择拼写之后,您似乎缺少一个冒号。魔术也拼错了。尝试将其更改为:

def choosespell(magic): #选择法术

于 2012-12-04T09:45:10.147 回答