Python Forum
simple dragon realm gone wrong
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
simple dragon realm gone wrong
#1
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()
Reply
#2
friendlyCave = random.randint(1, 2)... You meant cave = random.randint(1, 2)?
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#3
no its like that so that the friendly cave is the one which you compare the user imputted info against it.
Reply
#4
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
Reply
#5
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'
Reply
#6
Quote:
def checkCave(chosencave):

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

please tell me how to fix it thanks
Reply
#8
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...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 480 Nov-07-2023, 04:32 PM
Last Post: snippsat
  what's wrong? i know this is simple davidorlow 11 1,681 Mar-15-2023, 05:14 PM
Last Post: deanhystad
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,539 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  python gives wrong string length and wrong character thienson30 2 2,993 Oct-15-2019, 08:54 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020