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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:23:26+00:00 2026-05-20T23:23:26+00:00

hey guys. i am a bit stuck on something with ex42: from sys import

  • 0

hey guys. i am a bit stuck on something with ex42:

from sys import exit
from random import randint

class Game(object):

    def __init__(self, start):
        self.quips = [
            "You died.  You kinda suck at this.",
             "Your mom would be proud. If she were smarter.",
             "Such a luser.",
             "I have a small puppy that's better at this."
        ]
        self.start = start

    def play(self):
        next = self.start

        while True:
            print "\n--------"
            room = getattr(self, next)
            next = room()


    def death(self):
        print self.quips[randint(0, len(self.quips)-1)]
        exit(1)


    def princess_lives_here(self):
        print "You see a beautiful Princess with a shiny crown."
        print "She offers you some cake."

        eat_it = raw_input("> ")

        if eat_it == "eat it":
            print "You explode like a pinata full of frogs."
            print "The Princess cackles and eats the frogs. Yum!"
            return 'death'

        elif eat_it == "do not eat it":
            print "She throws the cake at you and it cuts off your head."
            print "The last thing you see is her munching on your torso. Yum!"
            return 'death'

        elif eat_it == "make her eat it":
            print "The Princess screams as you cram the cake in her mouth."
            print "Then she smiles and cries and thanks you for saving her."
            print "She points to a tiny door and says, 'The Koi needs cake too.'"
            print "She gives you the very last bit of cake and shoves you in."
            return 'gold_koi_pond'

        else:
            print "The princess looks at you confused and just points at the cake."
            return 'princess_lives_here'

    def gold_koi_pond(self):
        print "There is a garden with a koi pond in the center."
        print "You walk close and see a massive fin poke out."
        print "You peek in and a creepy looking huge Koi stares at you."
        print "It opens its mouth waiting for food."

        feed_it = raw_input("> ")

        if feed_it == "feed it":
            print "The Koi jumps up, and rather than eating the cake, eats your arm."
            print "You fall in and the Koi shrugs than eats you."
            print "You are then pooped out sometime later."
            return 'death'

        elif feed_it == "do not feed it":
            print "The Koi grimaces, then thrashes around for a second."
            print "It rushes to the other end of the pond, braces against the wall..."
            print "then it *lunges* out of the water, up in the air and over your"
            print "entire body, cake and all."
            print "You are then pooped out a week later."
            return 'death'

        elif feed_it == "throw it in":
            print "The Koi wiggles, then leaps into the air to eat the cake."
            print "You can see it's happy, it then grunts, thrashes..."
            print "and finally rolls over and poops a magic diamond into the air"
            print "at your feet."

            return 'bear_with_sword'

        else:
            print "The Koi gets annoyed and wiggles a bit."
            return 'gold_koi_pond'


    def bear_with_sword(self):
        print "Puzzled, you are about to pick up the fish poop diamond when"
        print "a bear bearing a load bearing sword walks in."
        print '"Hey! That\' my diamond! Where\'d you get that!?"'
        print "It holds its paw out and looks at you."

        give_it = raw_input("> ")

        if give_it == "give it":
            print "The bear swipes at your hand to grab the diamond and"
            print "rips your hand off in the process.  It then looks at"
            print 'your bloody stump and says, "Oh crap, sorry about that."'
            print "It tries to put your hand back on, but you collapse."
            print "The last thing you see is the bear shrug and eat you."
            return 'death'

        elif give_it == "say no":
            print "The bear looks shocked.  Nobody ever told a bear"
            print "with a broadsword 'no'.  It asks, "
            print '"Is it because it\'s not a katana?  I could go get one!"'
            print "It then runs off and now you notice a big iron gate."
            print '"Where the hell did that come from?" You say.'

            return 'big_iron_gate'

    def big_iron_gate(self):
        print "You walk up to the big iron gate and see there's a handle."

        open_it = raw_input("> ")

        if open_it == 'open it':
            print "You open it and you are free!"
            print "There are mountains.  And berries! And..."
            print "Oh, but then the bear comes with his katana and stabs you."
            print '"Who\'s laughing now!?  Love this katana."'

            return 'death'

        else:
            print "That doesn't seem sensible.  I mean, the door's right there."
            return 'big_iron_gate'


a_game = Game("princess_lives_here")
a_game.play()

play is confusing me, i get how next gets the first room, which is passed when the instance of Game() is created, but how does it get the next room?

thanks

  • 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-20T23:23:27+00:00Added an answer on May 20, 2026 at 11:23 pm

    Nice code.

    Just look at this snippt(it is part of play()):

    while True:
                print "\n--------"
                room = getattr(self, next)
                next = room()
    

    The getattr() line gets the function with the name next.
    So in the beginning it is the function with the name ‘princess_lives_here’

    The line next = room() executes the function and stores the name of the next room,
    which will be mapped to the function and executes in the next round.

    EDIT: You’re all pretty fast in answering questions. 😉

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

Sidebar

Related Questions

Hey guys, in the TTStyledTextLabel, the url's font is a bit bigger(from what i
Hey guys, I have a bit of a problem. I get values from textarea
Hey guys I need a tad bit of help. I need my streamwriter to
Hey guys, I'm having a bit of trouble with my ASP:RadioButtonList, searched Google and
Hey guys, I'm a bit confused about how multiple iterations of the tournament selection
Hey guys, this bit of code works in IE but not in Chrome, any
hey guys, just having a bit of difficulty with a query, i'm trying to
Hey guys, I have this quick bit of code that I can't figure out
Hey guys, I have a bit of a problem that I can't solve. I'm
Hey guys, I've struggled with this for a bit and don't seem to find

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.