Python program to find sum of two numbers without using arithmetic operators

Python program to find sum of two numbers without using arithmetic operators

sum of two numbers without using arithmetic operators using function

In this tutorial, we will discuss the concept of Python program to find sum of  two numbers without using arithmetic operators

In this post, we will learn how to make the addition of two number using without the arithmetic operator in Python programming language

Addition

Program 1

This program allows the user to enter two numbers and displays the sum of two numbers entered by the user

#Python program to add two numbers
#Without using arithmetic operator
a=int(input("Enter the number for a: "))
b=int(input("Enter the number for b: "))
def add(a,b):   #Create a function
    while(b != 0):#while loop

        c=a&b #and operator

        a=a^b #Xor operator

        b=c<<1
    return a

    
    
print("Sum of two numbers",add(a,b))  #call the function
#Display sum of two numbers

When the above code is executed, it produces the following results

Enter the number for a: 34
Enter the number for b: 54
Sum of two numbers 88

 

Methods

  • User inputs the first number
  • Store  the number in variable a
  • User inputs the second number
  • Store the number in variable b
  • Create a function with “while loop” used for addtion of two numbers.
  • Call the function
  • Display the sum of the numbers on the screen.

 

sum of two numbers without using arithmetic operators

Program 2

This program allows the user to enter two numbers and displays the sum of two numbers entered by the user

num1=int(input("Enter the first number"))
num2=int(input("Enter the second number"))
while num2 !=0:
        count=num1 & num2
        num1=num1^num2
        num2=count << 1
        
print("Sum of two numbers are",num1)

 

When the above code is executed, it produces the following results

Enter the first number: 123
Enter the second number: 345
Sum of two numbers are 468

 

Similar post

Python program to calculate the sum of two numbers

Python program to calculate the sum of two numbers using function

Python program to calculate sum of two numbers using recursion

 

Java program to find sum of two numbers without using arithmetic operators

C  program to find sum of two numbers without using arithmetic operators

C++ program to find sum of two numbers without using arithmetic operators

 

C program to add two numbers without using arithmetic operators

C++ program to add two numbers without using arithmetic operators

Python program to add two numbers without using arithmetic operators

Java program to sum of two numbers

C program to sum of two numbers

C++ program to sum of two numbers

Python program to sum of two numbers

C++ program to find the sum  of two numbers  using recursion

C program to find the sum  of two numbers  using recursion

Java program to find the sum  of two numbers  using recursion

Python program to find the sum  of two numbers  using recursion

 

 

 

Suggested for you

Python programming function

Python programming while loop

Python programming operator

Python programming datatype

Java program to add two numbers without using arithmetic operators
Java program to check whether a number is Positive or Negative or Zero
Python languagepython program
Comments ( 2 )
Add Comment
  • Mohammad Imran

    num1=int(input(“Enter the first number”))
    num2=int(input(“Enter the second number”))
    while num2 !=0:
    count=num1 & num2
    num1=num1^num2
    num2=count <>>
    That’s it…
    It seems something is missing!
    And, the source code you provided is wrong.

    Thanks…
    I hope you’ll correct it.

    • Karmehavannan

      num1=int(input(“Enter the first number:”))
      num2=int(input(“Enter the second number:”))
      while num2 != 0:
      count=num1 & num2
      num1=num1^num2
      num2=count<<1 print("Sum of",num1)