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 7499887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:58:32+00:00 2026-05-29T19:58:32+00:00

I just started learning Python a couple of days ago as my first language

  • 0

I just started learning Python a couple of days ago as my first language and I ran into some trouble while trying to make a game. Here’s the part I’m stuck at:
Primary concern: I want it to randomly generate objects and doors.
Secondary concern: I need each room to remember the objects even after I leave the room (Pots are destructible)

The problem: I want the program to spit out the number of pots,chests,superchests and doors , but the variables remain empty. Sorry for not framing the question more specifically, but I just started and the water is kinda murky in here D:

def random_room(pot, chest, schest, ldoor, rdoor, fdoor):
    import random
    loop = 0
    pot = 0
    chest = 0
    schest = 0
    ldoor = 0
    rdoor = 0
    fdoor = 0
    while loop < 6:       
        rand = random.randint(0, 30)
        if rand  in range(1, 3, 1):
            chest += 1
            loop += 2
            return chest
        if rand in range(4,10, 1):
            schest -= 1
            return schest
        if rand == 16:
            schest += 1
            loop += 3
            return schest
        if rand > 16:
            pot += 1
            loop +=1
            return pot
        if rand in range(10,12, 1):
            ldoor = 1
            return ldoor
        if rand in range(12,14, 1):
            fdoor = 1
            return fdoor
        if rand in range(14, 16, 1):
            rdoor = 1
            return rdoor
        if schest < 0:
            schest = 0
        if rdoor + fdoor + ldoor == 0:
            rand = random.randint(1,3)
            if rand == 1:
                rdoor += 1
            if rand == 2:
                ldoor += 1
            if rand == 3:
                fdoor += 1

random_room(pot, chest, schest, ldoor, rdoor, fdoor)
print pot
print ldoor
print rdoor
print fdoor
print chest
print schest
room = 2
while room == 2:    
    left_door = ""
    right_door = ""
    front_door = ""
    print "You enter a room."
    if chest == 1:
        print "There is one CHEST in the room."
    if chest > 1:
        print "There are", chest, "CHESTs in the room."
    if pot == 1:
        print "There is one POT in the room."
    if pot > 1:
        print "THere are", pot, "POTs in the room."
    if ldoor == 1:
        left_door = "a door to the LEFT"
    if rdoor == 1:
        right_door = "a door to the RIGHT"
    if fdoor == 1:
        front_door = "a door in the FRONT"
    if True:
        print "There's", left_door, ",", right_door, ", and", front_door
        break
  • 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-29T19:58:33+00:00Added an answer on May 29, 2026 at 7:58 pm

    Daniel, there are many problems with code that you have posted. I’ll try to outline as many of them as I can.

    First, parameters that are passed to a function generally provide a means of getting information into a function, not out of a function. Python does allow you to return multiple values from a function however, so instead of this:

    random_room(pot, chest, schest, ldoor, rdoor, fdoor)

    you want to say this:

    pot, chest, schest, ldoor, rdoor, fdoor = random_room()

    The next big problem is that return immediately exits a function, so when, inside your random_room function, you say:

     while loop < 6:       
            rand = random.randint(0, 30)
            if rand  in range(1, 3, 1):
                chest += 1
                loop += 2
                return chest
    

    The return chest immediately exits the function and returns only the value in the variable chest which will be given to the variable pot. However, if you remove all of the return statements that are inside the while loop, the loop will finish executing, and at the end, you can say:

    return pot, chest, schest, ldoor, rdoor, fdoor

    and all of the values will be returned to the code that called the random_room function.

    Finally, this code:

    room = 2
    while room == 2:
    

    is effectively meaningless and will only result in an infinite loop. Since there is no code inside the while loop that changes the value of the variable room, it will just keep printing over-and-over-and-over again. I think that you might have wanted to have the loop run a couple of times and print out the values for a couple of calls to random_room?

    If that’s the case, you probably want the code to look something like this:

    room = 0
    while room < 5: # Print five calls to random room
        pot, chest, schest, ldoor, rdoor, fdoor = random_room()
        # Code to print out values returned from random_room
        # ...
        room += 1
    

    As I said in the comments above, you need to do a lot more reading on Python and object-oriented Python. Python can be a very forgiving language in that it might not give you explicit errors when you try to run code that is syntactically legal but might not make much sense at all. Fortunately for you, python is very popular language, and there are a myriad of helpful resources on the web that you can take advantage of.

    Best of luck.

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

Sidebar

Related Questions

I am a beginner and just started learning Python couple days ago (yay!) so
I just started learning Common Lisp a few days ago, and I'm trying to
I just started learning Python (as my first language, so I know next to
I just started learning my first real programming language, Python. I'd like to know
I have just started learning Erlang and am trying out some Project Euler problems
I am just started out learning Python and also started looking into Django a
So ive just started learning python on WAMP, ive got the results of a
I´ve just started learning GWT and I´m trying to implement http://gwt.google.com/samples/Showcase/Showcase.html#!CwFileUpload and but failing
I just started learning C++ (coming from Java ) and am having some serious
I just started learning Python... I am writing a simple program that will take

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.