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

  • Home
  • SEARCH
  • 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 3951880
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:47:00+00:00 2026-05-20T01:47:00+00:00

I am on exercise 43 doing some self-directed work in Learn Python The Hard

  • 0

I am on exercise 43 doing some self-directed work in Learn Python The Hard Way. And I have designed the framework of a game spread out over two python files. The point of the exercise is that each “room” in the game has a different class. I have tried a number of things, but I cannot figure out how to use the returned value from their initial choice to advance the user to the proper “room”, which is contained within a class. Any hints or help would be greatly appreciated.

Apologies for the poor code, I’m just starting out in python, but at my wit’s end on this.

Here is the ex43_engine.py code which I run to start the game.


from ex43_map import *
import ex43_map
import inspect

#Not sure if this part is neccessary, generated list of all the classes (rooms) I imported from ex43_map.py, as I thought they might be needed to form a "map"
class_list = []
for name, obj in inspect.getmembers(ex43_map):
    if inspect.isclass(obj):
        class_list.append(name)

class Engine(object):

    def __init__(self, room):
        self.room = room 


    def play(self):
        # starts the process, this might need to go inside the loop below
        next = self.room      
        start.transportation_choice()

        while True:
            print "\n-------------"
            # I have tried numerous things here to make it work...nothing has

start = StartRoom()
car = CarRoom()
bus = BusRoom()
train = TrainRoom()
airplane = AirplaneRoom()
terminal = TerminalRoom()

a_game = Engine("transportation_choice")
a_game.play()

And here is the ex43_map.py code


from sys import exit
from random import randint

class StartRoom(object):
    def __init__(self):
        pass
    def transportation_choice(self):
        print "\nIt's 6 pm and you have just found out that you need to get to Chicago by tomorrow morning for a meeting"
        print "How will you choose to get there?\n"
        print "Choices: car, bus, train, airplane"
        choice = raw_input("> ")

        if choice == "car":
            return 'CarRoom'

        elif choice == "bus":
            return 'BusRoom'

        elif choice == "train":
            return 'TrainRoom'

        elif choice == "airplane":
            return 'AirplaneRoom'

        else:
            print "Sorry but '%s' wasn't a choice." % choice
            return 'StartRoom'


class CarRoom(object):

    def __init__(self):
        print "Welcome to the CarRoom"

class BusRoom(object):

    def __init__(self):
        print "Welcome to the BusRoom"

class TrainRoom(object):

    def __init__(self):
        print "Welcome to the TrainRoom" 

class AirplaneRoom(object):

    def __init__(self):
        print "Welcome to the AirplaneRoom"

class TerminalRoom(object):

    def __init__(self):
        self.quips = [
            "Oh so sorry you died, you are pretty bad at this.",
            "Too bad, you're dead buddy.",
            "The end is here.",
            "No more playing for you, you're dead."
            ]

    def death(self):
             print self.quips[randint(0, len(self.quips)-1)] # randomly selects one of the quips from 0 to # of items in the list and prints it 
             exit(1)  

  • 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-20T01:47:01+00:00Added an answer on May 20, 2026 at 1:47 am

    Instead of returning a string try returning an object, ie

        if choice == "car":
            return CarRoom()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm up to Exercise 41 in Learn Python the Hard Way, and I'm having
I'm doing Zed Shaw's Learn C The Hard Way course. On exercise 11, in
I'm doing exercise #9 from http://openbookproject.net/thinkcs/python/english2e/ch09.html and have ran into something that doesn't make
I am doing some exercise from a book and have some problems with the
I'm doing some python online tutorials, and I got stuck at an exercise:A palindrome
I'm doing some exercise to understand Java and Swing API. Why do I have
I have been doing some experimenting with iOS drawing. To do a practical exercise
im doing an exercise where i have to make a parking lot application. The
I am doing some exercises from the book Thinking In Java . I have
So I am going to be doing some work with R soon, and I

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.