Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 13 Online
OpenStudy (anonymous):

MIT 6.00 Spring 2011 PS5 Problems 6-8 : I have a couple of questions on this. First, in the instructions it says "should not be subclasses of WordTrigger." yet in the ps5-sol's ps5.py it uses "class NotTrigger(WordTrigger):" etc. In mine I have it as "class NotTrigger(Trigger):" and it seems to make no difference. Secondly, in these classes it defines an "evaluate" method with just a return statement that calls "evaluate". Now there is no "evaluate" method in "WordTrigger" and the one in "Trigger" simply returns an error so I am unclear how this works, although it does.

OpenStudy (anonymous):

Hmm. I'll check this up.

OpenStudy (anonymous):

Okay

OpenStudy (anonymous):

whoever wrote that solution did not read the instructions very closely did they.? looks like those composite triggers pass the tests though. they probably do not have to be subclasses of WordTrigger to pass the test. did you try it on your own before you looked at the solution? what did yours look like? the composite trigger constructors take Triggers for an argument - to construct a composite trigger you have to give it a previously defined Trigger/WordTrigger. The evaluate method of the composite triggers are calling the evaluate method of the Triggers that were passed to it as arguments

OpenStudy (anonymous):

I was trying to fix mine to work and realize that what they did was mostly right. bwCA, I did not fully understand what you meant until I put some print statements in my code and then analyzed the test code to see exactly what it did, but you are correct. I realized that the "trigger" that was sent to is was indeed another class and therefore could use it's "evaluate" method thus meaning the code is correct aside from it's subclassing but works either way. After I figured out what I was doing wrong, what you said makes absolute sense. I haven't worked much with classes so I was thinking of "trigger" as more of a string than a class.

OpenStudy (anonymous):

Okay

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!