python - What is wrong with my simple code here? -


hi having problems writing simple program. starting out python , hoping help. when run start() function @ bottom of programme, works fine until after first raw_input(). if user types "get coffee" example, string "fair enough take break" printed after this, rather running coffee() function like, loops through start() function again.

would able please? lot.

def engine(next_scene):     scenes = {"start":start(),"coffee":coffee(),"work":work()}     return scenes[next_scene]  def start():     print "you in office"     print "you wonder do"     action = raw_input("what do? coffee or work?")      if action == "get coffee":         print "fair enough take break"         next_scene = "coffee"         engine(next_scene)     if action == "work":         print "good man, on way being coder"         next_scene = "work"         engine(next_scene)  def coffee():     print "you walk out of room"     print "you head down stairs , cafe"     print "you order espresso"     print "you neck down"     print "yumm"     print "you wired"     action = raw_input("now what? work or go home? > ")      if action == "work":         print "you head upstairs"         next_scene = "work"         engine(next_scene)     if action == "go home":         print "you lazy git"  def work():     print "you beaver away , become cool coder"     next_scene = "start"     engine(next_scene)  start() 

this

scenes = {"start":start(),"coffee":coffee(),"work":work()} 

should be

scenes = {"start":start,"coffee":coffee,"work":work} 

you called functions in dictionary definition, want function object.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -