{"id":17009,"date":"2021-08-17T08:50:04","date_gmt":"2021-08-17T03:20:04","guid":{"rendered":"https:\/\/python-programs.com\/?p=17009"},"modified":"2021-11-22T18:37:21","modified_gmt":"2021-11-22T13:07:21","slug":"python-program-to-add-two-numbers-without-using-the-plus-operator","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-add-two-numbers-without-using-the-plus-operator\/","title":{"rendered":"Python Program to Add Two Numbers Without Using the \u201c+\u201d Operator"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Find out the Arc Length of an Angle<\/a> Formula :<\/strong><\/p>\n Let x, y are the given two numbers, then<\/p>\n x+y<\/strong> = x^2-y^2 = (x+y)(x-y)\u00a0 if\u00a0<\/strong>\u00a0 (x!=y).<\/p>\n x+y<\/strong> = 2*x\u00a0<\/strong> \u00a0 (\u00a0 if x=y )<\/p>\n Given two numbers and the task is to add the given two numbers without using the ‘+’ operator.<\/p>\n Examples:<\/strong><\/p>\n Example 1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:\u00a0<\/strong><\/p>\n Example 2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to add the given two numbers without using the ‘+’ operator.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:\u00a0<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:\u00a0<\/strong><\/p>\n Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n In the previous article, we have discussed Python Program to Find out the Arc Length of an Angle In order to add two numbers without using the ‘+’ operator, we should use a mathematical formula. Formula : Let x, y are the given two numbers, then x+y = x^2-y^2 = (x+y)(x-y)\u00a0 if\u00a0\u00a0 (x!=y). x+y = …<\/p>\n
\nIn order to add two numbers without using the ‘+’ operator, we should use a mathematical formula.<\/p>\nGiven First Number = 65\r\nGiven Second Number = 45<\/pre>\n
The sum of given two numbers = 110.0<\/pre>\n
Given First Number = 220.5\r\nGiven Second Number = 100<\/pre>\n
The sum of given two numbers = 320.5<\/pre>\n
Program to Add Two Numbers Without Using the \u201c+\u201d Operator.<\/h2>\n
\n
Method #1: Using Mathematical Formula (Static Input)<\/h3>\n
\n
# Give the first number as static input and store it in a variable.\r\nfst_num = 2.5\r\n# Give the second number as static input and store it in another variable.\r\nsec_num = 8\r\n# Check if the first number is not equal to the second number using the if conditional\r\n# statement.\r\nif fst_num != sec_num:\r\n # If the statement is true, then print\u00a0 the value of\r\n # (fst_num*fst_num-sec_num*sec_num)\/(fst_num-sec_num)\r\n print(\"The sum of given two numbers =\",\r\n (fst_num*fst_num-sec_num*sec_num)\/(fst_num-sec_num))\r\nelse:\r\n # Else print the value of (2*fst_num).\r\n print(\"The sum of given two numbers =\", 2*fst_num)\r\n<\/pre>\n
The sum of given two numbers = 10.5<\/pre>\n
Method #2: Using Mathematical Formula (User Input)<\/h3>\n
\n
# Give the first number as user input using the float(input()) function and \r\n#store it in a variable.\r\nfst_num = float(input(\"Enter some random number = \"))\r\n# Give the second number as user input using the float(input()) function and \r\n#store it in another variable.\r\nsec_num = float(input(\"Enter some random number = \"))\r\n# Check if the first number is not equal to the second number using the if conditional\r\n# statement.\r\nif fst_num != sec_num:\r\n # If the statement is true, then print\u00a0 the value of\r\n # (fst_num*fst_num-sec_num*sec_num)\/(fst_num-sec_num)\r\n print(\"The sum of given two numbers =\",\r\n (fst_num*fst_num-sec_num*sec_num)\/(fst_num-sec_num))\r\nelse:\r\n # Else print the value of (2*fst_num).\r\n print(\"The sum of given two numbers =\", 2*fst_num)\r\n<\/pre>\n
Enter some random number = 50\r\nEnter some random number = 70\r\nThe sum of given two numbers = 120.0<\/pre>\n
\n