Python Forum
simple dragon realm gone wrong - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: simple dragon realm gone wrong (/thread-2246.html)



simple dragon realm gone wrong - Darbandiman123 - Mar-01-2017

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



RE: simple dragon realm gone wrong - Ofnuts - Mar-01-2017

friendlyCave = random.randint(1, 2)... You meant cave = random.randint(1, 2)?


RE: simple dragon realm gone wrong - Darbandiman123 - Mar-01-2017

no its like that so that the friendly cave is the one which you compare the user imputted info against it.


RE: simple dragon realm gone wrong - Raymond_chang - Mar-01-2017

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


RE: simple dragon realm gone wrong - Darbandiman123 - Mar-01-2017

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'


RE: simple dragon realm gone wrong - nilamo - Mar-01-2017

Quote:
def checkCave(chosencave):

checkCave takes one parameter. You didn't pass any parameters.


RE: simple dragon realm gone wrong - Darbandiman123 - Mar-01-2017

dont really understand perameters

please tell me how to fix it thanks


RE: simple dragon realm gone wrong - nilamo - Mar-01-2017

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...