Basic Functions Question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Basic Functions Question

Really basic question - think I'm having a mental block - what do I need to do to make this work? def my_sum(a,b) Return (sum(a,b)) print my_sum my_sum(5,6) Hopefully bits obvious what I am trying to do. I can do it like this: def my_sum(a,b) Return a+b Print (my_sum(4,5)) I just wanted it all rolled up into an easier chunk. Thanks!

31st Mar 2020, 12:46 PM
Andrew Chadwick
Andrew Chadwick - avatar
3 Answers
0
def my_sum(a,b): return a+b print(my_sum(5,7)) #Return syntax error. Use small r in return #also small in print()
31st Mar 2020, 1:06 PM
Jayakrishna 🇮🇳
0
Yeh sorry ignore the capital letters - it was just my phone. I still can't get it to work with the print in the function rather than out of it
31st Mar 2020, 3:21 PM
Andrew Chadwick
Andrew Chadwick - avatar
0
If you want to print in function, write before return statement. If return statement executed, then control comes back to called function. statement after return call, never executed... def my_sum(a,b): print(a+b) return my_sum(5,7)
31st Mar 2020, 4:19 PM
Jayakrishna 🇮🇳