dragon.py运行后没有错误消息

时间:2017-05-19 17:21:55

标签: python python-idle game-development

我目前正在开始使用“Invent Your Own Computer Games w/ Python”一书,&出于某些奇怪的原因,尽管进行了多次检查和找到不止一些失误(误导变量,使用';'当':'是必需的等等)时,dragon.py的类型拒绝在IDLE中运行。

更糟糕的是,我没有收到错误消息;它只显示"RESTART: /Users/yosemite/Documents/dragon.py",然后我回到提示符处。然而,该网站的正式版here运行完全正常。

任何人都知道我在这里做错了什么?更新:这是我的代码,以前忘了包含它:

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 reasure with you.  The other dragon')
    print ('is greedy and hungry, and will eat 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 ('A Large dragon jumps out in front of you!  He opens his jaws 
    and...')
    print()
    time.sleep(2)

    friendlyCave = random.randint(1, 2)

    if chosenCave == str(friendlyCave):
        print('Gives you his treasures!')
    else:
        print('Goobles you up in onebite!')

    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()

1 个答案:

答案 0 :(得分:0)

您发布的代码,一旦缩进正确,导入两个模块,定义三个函数,然后结束。程序结束时显示提示是IDLE应该做的事情。

最后添加以下函数调用将继续执行。

checkCave(chooseCave())

如果您使用

从(mac?)控制台运行程序
python -i /Users/yosemite/Documents/dragon.py

您会看到相同的行为,即>>>提示符的外观。