Loading...

I'm trying to do th… - QuestionCove
OpenStudy (anonymous):

I'm trying to do the exercise Wk.3.1.4. of Software Lab 3. Part 1: Maximize. I've solved it with the following functions: >>> def maxim(tuple): return max (tuple [0], tuple [1]) >>> def maxAccount (sm1, sm2): sm.Cascade return (sm.Parallel (sm1, sm2), sm.PureFunction (maxim)) Do you agree the solution? Part 2: Investment I've thought something like >>> def greaterThan3000 (x): return x > 3000 >>> def switchAccount(sm1,sm2): return sm.Mux(greaterThan3000, sm1,sm2) but if I do: >>> b=switchAccount(ba1,ba2) >>> b.transduce(3001,1,3001,1) it returns type 'int' has no len(). Any idea?

5 years ago
OpenStudy (anonymous):

Part 1: No need to define maxim(tuple). The max() bult-in function can handle tuple (of 2 items). I do the same state machine composition. Part 2: Aha. How about b.tranceduce([3001, 1, 3001, 1]) Such little mistakes are always annoying :D BTW, using sm.Mux causes problem here. Mux will deliver the inp to both sm1 and sm2, which means you deposit the money to both ba1 and ba2 in one time! BTW again, I suggest a handy way to define simple function. The lambda expression. You may have seen it in the course notes. For example, in your codes, sm.Mux(greaterThan3000, sm1,sm2) can be replaced by sm.Mux(lambda x: x>3000, sm1,sm2). You may want to look up the python document for details.

5 years ago
OpenStudy (anonymous):

Thank you very much for your explanations. These little mistakes ended up with my health. I had already seen as the lambda function works but I do not like too much because it is too exclusive of Python. In any case, thanks for your comments.

5 years ago
Similar Questions: