Exercise 43, code won't run

Below is my code and I am just trying to get the CentralCorridor scene working. But nothing happens when I run it from terminal, no error message is presented. Why?

from sys import exit
from random import randint

class Scene(object):
	
	def enter(self):
		print "This scene is not yet configured. Subclass it and implement enter():"
		exit(1)

class Engine(object):
	
	def __init__(self, scene_map):
		pass
		
	def play(self):
		pass
		
class Death(Scene):
	
	def enter(self):
		pass
		
class CentralCorridor(Scene):
	
	def enter(self):
		print "You stand in the central corridor, and a Gothon is present. Select a joke 1, 2 or 3. It has to be funny for the Gothon to be defeated."
		print "1: You are green"
		print "2: Seinfeld is fun"
		print "3: Python is a bad language" 
		
		alternative = raw_input("> ")
		
		if alternative == "1":
			print "Joke not funny, gothon kills you. Game over"
		elif alternative == "2":
			print "Joke not funny, gothon kills you. Game over"
		elif alternative == "3":
			print "Gothon dies as a result of your funny joke"
			TheBridge()
			
		else:
			print "DOES NOT COMPUTE"
			return 'central corridor'
			
		
class LaserWeaponArmory(Scene):
		
	def enter(self):
		pass
	
class TheBridge(Scene):

	def enter(self):
		pass
		
class EscapePod(Scene):
	
	def enter(self):
		pass
		
class Map(object):

	scenes = {
	'central_corridor': CentralCorridor(),
	'laser_weapon_armory': LaserWeaponArmory(),
	'the_bridge': TheBridge(),
	'escape_pod': EscapePod(),
	'death': Death()
	}

	def __init__(self, start_scene):
		pass
	
	def next_scene(self, scene_name):
		pass
		
	def opening_scene(self):
		pass

		
a_map = Map('central_corridor')
a_game = Engine(a_map)
a_game.play()

Hi @Trezor.

I think you will find some kind of answer in a reply to your other question
Exercise 43, some explanation needed

Have a look and see if it is useful.

Hi @Trezor I will kindly ask you to read this post below. Thank you.

I think I also see something I’m positive you’re doing. Are you writing a bunch of code and then trying to run it? See I think that’s the case because, if you look at your Engine class your Engine.play function is totally empty. How would Engine.play possibly do something if it’s empty?

Now, if you were building this up slowly a little bit at a time you would have done this:

  1. Written some engine Engine.play code.
  2. Done a bit of code to run Engine.play.
  3. Run it.
  4. See that it doesn’t run, go back and fix it.
  5. Write some more Engine.play code.
  6. Repeat, until Engine.play is mostly working, and then do the same incremental process with more code.

What you have here is close, but now you just have to go and write the Engine.play code and constantly keep running the code to make sure it works.

This is kind of a misconception of programming. I always run my code while I’m coding. I assume every single thing I write is not going to work and then I go run it. I think people believe they should write a lot of code and then run it because they’re used to “writing” for classes, where you write an essay and then edit it. In programming, you should be running the code after only 2-6 lines of code are written.

The other thing you’ll want to do is try to think through and solve problems on your own before asking for help. That’s not meant to shove you off, but it’s mean to help you hone your skills of debugging. You can’t constantly run to get help at the first sign when you’re working as a programmer because you’re literally paid to solve problems on your own. So, start setting a time of about 2 days of trying to solve it on your own.

Finally, “solve it on your own” doesn’t mean sitting there staring at the code. YOU HAVE TO RUN CODE AND CHANGE CODE TO FIX CODE. This is so important. Don’t stare at it. Try changing something. List all the things you’ve tried and try something different.

Hey @zedshaw this advice is very solid and I learned to code like this from you and write code always like this. It is really easy to do in scripting languages like Pyhton or JS. But how do you do it in a compiled language like C or Java? Do you have to compile everything all the time? Wouldn’t that be very time consuming? I never programmed in a compiled language so I may missinterpreting something.

My computer is very fast so it compiles things very fast. If it’s some monsterous C++ project then that’s another matter, like if I had to compile all of Qt just to test it that’d be a nightmare. But, there’s tools like Make which knows how to recompile only the things that changed, and there’s tools that can cache previous compilations to speed them up.

But yes, I run my tests and recompile all the time. I also review my code before I compile to see if I can spot anything that would cause an error before I run the compiler.

1 Like

Thanks for clarifying this. So there is no reason at all to not follow that practice.

When you get more advanced “run your code” means “run the test suite”, but otherwise, yep I do this all the time.

1 Like

Oh, and I thought I had an excuse to slack off :slight_smile:

1 Like

I paint while the tests run.

1 Like