Python Forum

Full Version: simple dragon realm gone wrong
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i have a dragon realms game that wont go past asking you what cave to go in here is the code
#this is dragon realms

import time
import random

def displayintro():
    print('You arrive outside of 2 caves')
    print('in 1 cave there is a horrible dragon that wants to kill you, and in the other one there is a friendly dragon who will give you all his money and treasures.')

def choosecave():
    cave = ''
    while cave != ('1') or cave != ('2'):
        cave = input('Which cave will you go into? 1 or 2.')

def checkCave(chosencave):
    print('You walk towards the cave...')
    time.sleep(2)
    friendlyCave = random.randint(1, 2)
    if friendlyCave == cave:
        print('A dragon comes out and... gives you all its treasure!')
    elif friendlyCave != cave:
        print('A dragon comes out and... eats you!')

playAgain = 'yes'
while playAgain == 'yes':
    displayintro()
    caveNumber = choosecave()
    checkCave()
    print('Do you want to play again?')
    playAgain = input()
friendlyCave = random.randint(1, 2)... You meant cave = random.randint(1, 2)?
no its like that so that the friendly cave is the one which you compare the user imputted info against it.
seems like your script doesn't jump out the loop where u choose a cave

def choosecave():
    cave = ' '
    while cave not in ['1', '2']:
        cave = input('Which cave will you go into? 1 or 2.')
        if str(cave) in ['1', '2']:
            break
ok thanks. i did that but still got a error here it is

Traceback (most recent call last):
 File "C:/Python33/Python Coding/choose your own adventure/dragon realms.py", line 30, in <module>
   checkCave()
TypeError: checkCave() missing 1 required positional argument: 'chosencave'
Quote:
def checkCave(chosencave):

checkCave takes one parameter. You didn't pass any parameters.
dont really understand perameters

please tell me how to fix it thanks
Imagine a function as a machine on an assembly line. Some stuff comes down the assembly line, the machine does something to that stuff, and then that thing keeps on rolling down the line once the machine is done. A parameter is what you give to the function to work on, and the return value is what it gives you back once it's done. In this case, checkCave() is setup to receive the chosencave. So when you call checkCave, you'd need to pass it the chosencave. Like so: checkCave(caveNumber).

For reference, here's that function:
def checkCave(chosencave):
    print('You walk towards the cave...')
    time.sleep(2)
    friendlyCave = random.randint(1, 2)
    if friendlyCave == cave:
        print('A dragon comes out and... gives you all its treasure!')
    elif friendlyCave != cave:
        print('A dragon comes out and... eats you!')
In this particular case, you never actually use that parameter in the function. So... instead of comparing friendlyCave == cave, maybe you'd change it to friendlyCave == chosencave...