addition

Python code to Add two integer using without + operator

Python code to Add two integer using without + operator

In this article, we will discuss the concept of the Python code to Add two integer using without + operator

In this post, we are going to learn how to  write a program to find the sum of two numbers using without plus operator in Python programming language

Code to find the sum of  two numbers 

Sum of two integer using with – operator

The program allows the user to enter two integers and then calculates the sum of given  numbers using minus operator in Python language

Program 1

num1=int(input("Enter first number: "))
#ask input from user for num1
num2=int(input("Enter second number: "))
#ask input from user for num2
ans=num1-(-num2)
#Calculate the addition 
print("Sum of two numbers is",ans)
#display output on the screen

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

Enter first number: 259
Enter second number: 245
Sum of two numbers is 504

 

Sum of two integer  using bitwise operator

The program allows the user to enter two integers and then calculates the sum of given  numbers using Bitwise operator in Python language

Program 2

num1=int(input("Enter the first number: "))
#ask input from user for num1
num2=int(input("Enter the second number: "))
#ask input from user for num2
while num2 !=0:
        count=num1 & num2
        num1=num1^num2
        num2=count << 1
        
print("Sum of two numbers is",num1)
#display result on the screen

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

Enter the first number: 1000
Enter the second number: 300
Sum of two numbers is 1300

 

Sum of two integer using Bitwise with function

The program allows the user to enter two integers and then calculates the sum of given  numbers using Bitwise operator with function in Python language

Program 3

num1=int(input("Enter first number: "))
num2=int(input("Enter second number: "))
def add_without_Plus(num1,num2):#function definition
    while num2 !=0:
        count=num1 & num2
        num1=num1^num2
        num2=count << 1
    return num1
print("Sum of two numbers are",add_without_Plus(num1,num2))
#Calling the function and the result displays on the screen

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

Enter first number: 1234
Enter second number: 4321
Sum of two numbers are 5555

 

Suggested for you

Operator in Python language

Data type in Python language

if statements in Python language

Function in Python language

 

Similar post

Subtract two numbers in  Python  language

Subtract two numbers using function in Python language

Find sum of two numbers in Python Language

Find sum of two numbers in Python using recursion

Find sum of two numbers in Python without Arithmetic operator

Find sum of natural numbers in Python  language

Find sum of natural numbers in Python language using recursion

Sum of two integer using without + operator in C
C++ code to Add two integer using without + operator
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

1 day ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago