- 2

Why are these numbers repeating 20 times?

def multi(a,b): return a*b def t(z,a,b): return z(z(a,b),(a,b)) c=4 d=5 print(t(multi,c,d)) Output== (4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5)

16th Mar 2021, 8:43 AM
Nafi Rahat Rahman
4 Answers
+ 2
because you provide result of z(a,b) as first argument of outer z() call, and (a,b) tuple as second argument, so final result is tuple*20
16th Mar 2021, 8:47 AM
visph
visph - avatar
+ 4
You passed in a tuple (a, b) the tuple is multiplied by a*b. So -> 4 * 5 = 20 -> 20 * (4, 5) = (4, 5....)
16th Mar 2021, 8:47 AM
Abir Hasan
Abir Hasan - avatar
+ 1
Instead use return z(z(a, b), z(a, b))
16th Mar 2021, 8:48 AM
Abir Hasan
Abir Hasan - avatar
0
Great Explanation ... Abir Hassan :)
16th Mar 2021, 8:53 AM
Nafi Rahat Rahman