2017-05-19 3 views
0

を実行した後、私は現在、いくつかの失言(使用して、変数をmispellingより見つける複数のチェック&にもかかわらず、いくつかの奇妙な理由で、「Invent Your Own Computer Games w/ Python」の本、&を始めています「;」 ' : 'が必要です、など)、私のタイプアップdragon.pyはIDLEでの実行を拒否します。エラーメッセージdragon.pyが

さらに悪いことに、エラーメッセージが表示されません。単に"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() 
+6

コードを投稿してください。 – FamousJameous

+4

また、明らかに、その本のコードサンプル用の差分ツールがあります。 [このページ](https://inventwithpython.com/diff/?p=dragon)に移動して、コードを入力し、何が違うかを確認してください。 – FamousJameous

+0

ようこそStackOverflowへ。 [再現可能な例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)が役に立ちます。 – polka

答えて

0

あなたが投稿コードは、一度インデント適切に、輸入二つのモジュールを、3つの機能を定義し、終了します。プログラムの終了時にプロンプ​​トを表示するのは、IDLEが行うことです。

最後に次の関数呼び出しを追加すると、実行が開始されます。

checkCave(chooseCave())

あなたはあなたが、>>>プロンプトの外観を同じ振る舞いを見ているだろう

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

で(MAC?)コンソールからプログラムを実行した場合。