python - Won't print if I feedback into a function -
so have code create list @ start , ask user if wants make object (turtle), in case adds list, or if wants move turtle (x). if user has not created object want print 'need create object'. here code.
adventurousch = [] def roamingturtles(): command = raw_input("---> ") if command == 'a': newadventureturtle() roamingturtles() if command == 'x': if adventurousch == []: print "need create object" roamingturtles() else: in adventurousch: i.drawsquare() print "test" if have no roamingturtles() after print prints out successfully. i.e
if command == 'x': if adventurousch == []: print "need create object" but if add in no longer prints. i.e
if command == 'x': if adventurousch == []: print "need create object" roamingturtles() shouldn't print statement first feedback function? confused. want print'need create object' feedback function can create object.
your code does print need create object each time enter x @ prompt. see ipython transcript:
in [41]: %cpaste pasting code; enter '--' alone on line stop or use ctrl-d. :adventurousch = [] : :def roamingturtles(): : command = raw_input("---> ") : if command == 'a': : newadventureturtle() : roamingturtles() : if command == 'x': : if adventurousch == []: : print "need create object" : roamingturtles() : else: : in adventurousch: : i.drawsquare() : print "test" :<eof> in [42]: roamingturtles() ---> x need create object ---> x need create object ---> x need create object ---> so, if actual code different code posted… just use code posted, works.*
* well, works far particular problem.
Comments
Post a Comment