> Python programming, functiions help! so confused!?

Python programming, functiions help! so confused!?

Posted at: 2014-12-18 
checkCave(caveNumber) this is the key. U pass cavenumber to the function checkcave which for its own use is stored as chosencave. Parameter is chosencave. Arguement is cavenumber if I remember correctly. Its fairly common otherwise every variable ud want to use in any other function needs to be global and that can be tons of variables

problem figuring out what checkCave(chosenCave) funtion is. why is there a parameter instead of blank () like most functions? we dont define (chosenCave) and the book explanation below makes NO sense to me i swear ive read it 100 times and it makes zero sense, can someone please explain why this part of the code works?

When we call checkCave(), we will also pass one value to it as an argument. When execution

moves inside the checkCave() function, a new variable named chosenCave will be

assigned this value. This is how we pass variable values to functions since functions cannot read

variables outside of the function (that is, outside of the function's local scope).

Parameters are local variables that get defined when a function is called. The value stored in the

parameter is the argument that was passed in the function call.

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