+ 2

Why is this code written this way instead of this way?

For this activity: https://code.sololearn.com/339/#py I re-wrote it and I believe that it does the same thing, I'm not sure: def add(x, y): return x + y def do_twice(placeholder, x, y): return ((x + y) + (x + y)) a = 5 b = 10 print(do_twice(add, a, b)) And why does it work with placeholder and not without?

6th Jul 2017, 11:15 PM
William Davis-Watkins
William Davis-Watkins - avatar
3 Respostas
+ 3
because you pass add as the first parameter of do_twice Here do_twice should have return : return placeholder(placeholder(x,y),placeholder(x,y))
6th Jul 2017, 11:29 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 1
thanks bro. it makes sense now, I'm a true beginner, I've never did any programming before. I get this concept now.
14th Jul 2017, 3:03 AM
William Davis-Watkins
William Davis-Watkins - avatar
+ 1
You're welcome :) Do not worry, with practice you will improve fast :)
14th Jul 2017, 8:58 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar