0

我正在阅读这本书,用 Python 发明你自己的电脑游戏。它使用 python 3。我在 ubuntu 上使用 python 版本。

sayth@sayth-TravelMate-5740G:~$ python3 --version
Python 3.2.3

我在做 dragon.py - Dragon.py 作者源 这是我的源。

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 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 in to? (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 and...')
    print()
    time.sleep(2)

    friendlyCave = random.randint(1, 2)

    if chosenCave == str(friendlyCave):
        print('Gives you his treasure')
    else:
        print('Gobbles you up in one bite')

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

不,当我运行程序时,我什么也没得到,没有错误或工作程序。

sayth@sayth-TravelMate-5740G:~$ python3 dragon2.py 
sayth@sayth-TravelMate-5740G:~$ 

我检查了作者的差异工具差异工具,我很好。我使用 pep8 并且没问题。

你如何解决这个问题?什么是错的,显然没有要修复的错误。

4

2 回答 2

1

你可能想检查你的缩进(提示:从playAgain = 'yes'开始)。

于 2013-09-08T01:56:55.787 回答
0

我是这本书的作者。您还可以使用http://inventwithpython.com/diff/上的“在线差异工具”来查看您的代码与书中代码之间的任何差异。此比较将显示您所做的任何拼写错误。

于 2014-11-01T00:46:03.737 回答