# Python program to add two numbers

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

In this article, we will learn about the solution and approach to solve the given problem statement.

## Problem statement

We will be given two large numbers and we need to add them and display the output.

The bruteforce approach will be using the “+” operator between the operands or we can store two numbers in an iterable and use the inbuilt sum function available in Python standard library.

In this approach, time complexity is increased as the computation takes place on decimal numbers directly.

Now lets’s discuss another approach that involves working on the bits of the decimal numbers.

Here we will use the concept of adders that computes the sum and the carry .

Now let’s see the implementation −

## Example

Live Demo

def Add(x, y):
# carry becomes null
while (y != 0):
# carry with common bits
carry = x & y
# Sum of bits of x and y
x = x ^ y
# Carry is shifted by one
y = carry << 1
return x
print(Add(19, 34))

## Output

53

All variables and functions are declared in the global scope as shown in the figure below.