0

I'm currently beginning the "Invent Your Own Computer Games w/ Python" book, & for some odd reason, despite multiple checks & finding more than a few gaffes (mispelling a variable, using an ';' when ':' is required, etc.), my type up of dragon.py refuses to run in IDLE.

Worse, I'm not getting an error message; it simply displays "RESTART: /Users/yosemite/Documents/dragon.py" and I'm back at the prompt. The official version from the site, found here, however, runs perfectly fine.

Anyone have any idea what I'm doing wrong here? Updated: Here is my code, previously forgot to include it:

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()
Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52

1 Answers1

0

The code you posted, once indented properly, imports two modules, defines three functions, and then ends. Displaying the prompt when the program ends is what IDLE is supposed to do.

Adding the following function call at the end gets execution going.

checkCave(chooseCave())

If you had run you program from the (mac?) console with

python -i /Users/yosemite/Documents/dragon.py

you would have seen the same behavior, the appearance of a >>> prompt.

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52