jeudi 22 septembre 2016

Difficulty in defining a higher-order function to mimic if statement

I apologize in advance for the poor presentation (I'm new to this site and haven't read the post guidelines). Anyway, I have been hard pressed to answer a question we were recently asked as part of an exercise on higher-order functions in Python.

The question is to define two functions, one which takes no arguments, and passes three globally defined functions, c(), t() and f(), through if/else statements (if c() true, return t() else return f()). The other function is a higher-order function that we evaluate on c(), t() and f() that then passes them through the same if/else statements.

These functions are different and our task is to see how by defining three functions c(), t() and f() such that the first function returns 1 and the second returns something other than one.

So far I have come to the realization that the issue lies with the calling of the functions c(), t() and f() before passing them through the if/else statements. This however has not been enough to inspire a solution. Would anyone be able to steer me in the correct direction? Thanks in advance

Aucun commentaire:

Enregistrer un commentaire