Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7029581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:33:28+00:00 2026-05-28T00:33:28+00:00

I have the following script that is taken from a python game development book.

  • 0

I have the following script that is taken from a python game development book. The author explains everything, except for one thing. I tried to figure it out myself, but as a beginner it is not making much sense. Here is the code:

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

Now my question is this: how does the parameter chosenCave get a value? To me it seems that it wasn’t defined anywhere. We defined what cave is and what friendlyCave is, but not chosenCave. What is happening here? What am I missing?

Sorry if this is a complete beginner question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:33:29+00:00Added an answer on May 28, 2026 at 12:33 am

    The parameter chosenCave receives its value when the checkCave function is invoked. Prior to that it doesn’t have a value.

    When you define a function you have to option to declare parameters to that function. That’s where you see chosenCave in the parenthese next to the name of the function. Those parentheses create what is formally called the “Formal Parameter Declaration”. It defines how someone would call your method. It doesn’t actually invoke the method, but it just tells everyone how to call it.

    Down in the bottom section of the code you see this code:

    caveNumber = chooseCave()
    checkCave(caveNumber)
    

    That is called the “Actual Parameter Declaration”. Its a fancy way of saying this is what the actual value of chosenCave will be. In your example, chosenCave has been assigned the value of what’s in the variable caveNumber.

    Now that doesn’t mean chosenCave is forever more one value. It just means that during this execution of the function it’s a specific value. Every time you invoke a function a new value could be assigned to chosenCave. For example, the user could choose cave 1, get some treasure, say yes to play again, and then choose cave 2. That’s two invocations of checkCave. First is checkCave( 1 ), and the second is checkCave( 2 ). The value of chosenCave can change with each invocation of the function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following simple python test script that uses Suds to call a
I have a Python script that pulls in data from many sources (databases, files,
I have the following code (taken from actual script): $result=mysql_query($sql); while($row=mysql_fetch_assoc($result)) { $auth_token=$row['oauth_token']; $auth_token_secret=$row['oauth_token_secret'];
I have a calc function in java script that takes three integer parameters, following
I have the following script that works well in Firefox and Chrome (not sure
I have the following script that changes my image on a timer: var da
I have the following situation. I have a PHP script that imports a CSV
I have a PHP script that does the following: Uses file_get_contents() to get content
I have a CGI script that prints the following on stdout: print Status: 302
I have written a KornShell (ksh) script that sets an array the following way:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.