+ 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?
3 Réponses
+ 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))
+ 1
thanks bro. it makes sense now, I'm a true beginner, I've never did any programming before. I get this concept now.
+ 1
You're welcome :)
Do not worry, with practice you will improve fast :)