212k views
21 votes
Write a function that takes two arguments and returns their sum.

In the main part of your program (the part that isn't inside a function), call your
function to test it out.

1 Answer

10 votes

Answer & Explanation #1

To answer your first query. You can write a function that takes two arguments and returns their sum like this:

#Python program to add two numbers using a function

def add_num(a,b): #function for addition

sum=a+b

return sum #return value

num1=25 #variable declaration

num2=55

print("The sum is",add_num(num1,num2)) #call the function

Answer & Explanation #2

As for your error, I believe it is an indent error in your first return statement. All you must do is indent the return statement.

User Jisson
by
8.5k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.