+ 4
Callable function
I need help with this code. https://code.sololearn.com/cR4Ek18FgH5k/?ref=app
37 odpowiedzi
+ 7
This link has some meaningful solution in python with some good approach have an look if this help Tomiwa Joseph
https://www.sololearn.com/post/355059/?ref=app
+ 5
Wow, XXX, nice! 😁
It would be great if we got the actual number in the end, so that you could write something like:
n: int = add(1)(2)
+ 4
I couldn't think of a solution better than HonFu 's answer. But if callable classes are okay, you can do something like this
https://code.sololearn.com/ckKYGh7RH1RG/?ref=app
+ 4
HonFu that would be nice. But I can't think of a solution to that. Any suggestions??
Edit: The only thing I can think of is using the 'with' statement (updated the code to reflect that).
+ 4
XXX, unfortunately not!
In my mind, the function would have to know in time, if it will be called again - which obviously isn't really possible.
I'm sure there is a trick, but I don't see it.
+ 4
Wow, so simple! 😶
That guy knows his way around the Py. 😁
+ 4
HonFu Yes that's right.
But let me know if this is possible? Or am I just disturbing my brain?
+ 3
Hm, tricky. I'm at a loss so far. 😅
This is the closest I've come:
def add(call=None, n=[]):
if call:
n.append(call)
return add
return sum(n)
But it only works with an empty call at the end:
print(add(2)(3)(7)())
Something with closure... maybe... or... 🤔🤯
+ 3
If I try to use the function a second time, I get an error.
+ 3
Two possibilities:
1.) You make it. Then it was possible.
2.) You give up. Then you'll always wonder: Would it have been possible or not?
The general task is solvable, the aforementioned solution, inheriting from int, just great.
That doesn't necessarily mean there's no other way to do it.
+ 2
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 it was in the original code that the problem was in.
Trying to pass a second argument outside of a function call.
All i did was move a number back in to the call. Check OPs code
+ 2
I think we should check this kata out
https://www.codewars.com/kata/539a0e4d85e3425cb0000a88/train/JUMP_LINK__&&__python__&&__JUMP_LINK
+ 2
Waoh, 😳😳 really close infact. Good job HonFu It is indeed tricky.
+ 2
This is another cool way to go about it XXX waoh 😀. Thanks guys. There is just so much...too much to learn.
+ 2
Really appreciate this Preity
+ 2
Tricker that's not really a solution to the problem. What if you want to use the function in the interactive mode.
+ 2
I think this is more easier:
https://code.sololearn.com/cSX2ibOpHaPb/?ref=app
+ 2
HonFu sorry, I don't get you.