Including two numbers in Python: Here, we will learn different approaches to discover the addition of two numbers in python.
Take contribution of two numbers from the client and print their total.
Example:
Input:
A = 2, B = 3
Output:
Sum = 5
Here, we are actualizing the program to discover the addition of two numbers utilizing 4 distinct ways.
1) Simply take contribution from the client and pigeonhole to an integer simultaneously after that performing addition activity on both number.
if __name__ == "__main__" :
# take input from user
a = int(input())
b = int(input())
# addition operation perform
sum_num = a + b
print("sum of two number is: ",sum_num)
Output:
10
20
sum of two number is: 30
2) Using a client characterized work for doing a total of two numbers.
# define a function for performing
# addition of number
def sum_num(a,b) :
return a + b
# Main code
if __name__ == "__main__" :
a = int(input())
b = int(input())
print("sum of two number:",sum_num(a,b))
Output:
10
20
sum of two number: 30
3) We are taking the contribution from a client in one line after that
pigeonhole into an integer and put away them in the rundown at that point use whole() inbuilt capacity which restores the total of components of the rundown.
if __name__ == "__main__" :
# take input from the user in list
a = list(map(int,input().split()))
# sum function return sum of elements
# present in the list
print("sum of two number is:",sum(a))
Output:
10 20
sum of two number is: 30
4) We are taking the contribution from a client in one line and store them in two distinct factors at that
point pigeonhole both into an integer at the hour of additional activity.
if __name__ == "__main__" :
# take input from the user in a and b variables
a,b = input().split()
# perform addition operation
rslt = int(a) + int(b)
print("sum of two number is:",rslt)
Output:
10 20
sum of two number is: 30