Add two number in python by R4R Team

program -

#add two number by seperate function
def add(a,b):
return a+b
a=int(input("Enter first numbern"))
b=int(input("Enter second numbern"))

#add and print
print("Sum is "+str(a+b))

#add by function calling
ans=add(a,b)
print("sum is "+str(ans))
print(add(a,b))


output-

Enter first number
2
Enter second number
6
Sum is 8
sum is 8
8

In this program, we take two value as a input from the user and our aim to calculate the sum of the two input number so we make function add() which add two values and return the sum, so when we want to add two number we always call this function instead of written the code again.

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!