我有以下脚本是从Python游戏开发书中提取的。作者解释了一切,除了一件事。我试图自己弄清楚,但作为一个初学者,这没什么意义。下面是代码:这个特定参数如何获得一个值?
import random
import time
def displayIntro():
print('You are on a planet full of dragons. In front of you,')
print('you see two caves. In one cave, the dragon os 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 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(3)
friendlyCave=random.randint(1,2)
if chosenCave==str(friendlyCave):
print('Gives you his treasure!')
else:
print('Gobbles you down 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()
现在我的问题是:如何在参数chosenCave
获得价值?对我来说,它似乎没有在任何地方定义。我们定义了什么是cave
,什么friendlyCave
是,但不是chosenCave
。这里发生了什么?我错过了什么?
对不起,如果这是一个完整的初学者问题。
哦,这很有道理。谢谢,今天早些时候我实际上已经停留了几个小时。 – 2012-01-10 03:37:54