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

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago