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