Notice: Undefined offset: 15507353 in /var/www/html/qa-external/qa-external-users.php on line 744

Notice: Undefined offset: 15775479 in /var/www/html/qa-external/qa-external-users.php on line 744
the answer is coming ab like a =3 , b = 4 answer is coming 34 - OnlineGDB Q&A
Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

closed the answer is coming ab like a =3 , b = 4 answer is coming 34

+13 votes
asked May 26, 2025 by Yug Vijay (220 points)
closed Jul 3, 2025 by Admin
a = input("enter no. 1")

b = input("enter no. 2")

c = (a + b)

print (c)
closed with the note: answered

6 Answers

+4 votes
answered May 27, 2025 by Er. Gangaram (280 points)
a = int(input("enter no. 1: "))

b = int(input("enter no. 2: "))

c = (a + b)

print (c)
0 votes
answered Jun 3, 2025 by Prince Kumar Gupta (150 points)
a=input (int("enter first number :"))

b=input(int("enter second number :"))

print (a+b)
+3 votes
answered Jun 3, 2025 by Peter Minarik (101,340 points)
edited Jun 18, 2025 by Peter Minarik

Er. Gangaram told you how to fix your code.

I just wanted to give a short explainer. ;)

input returns a string, a text. When you do a + b and both of them are strings, then the result is a string concatenation, that is, putting the strings after one another. This is why your result is "3" + "4" = "34", a string.

If you want to treat your values as integral numbers, you need to cast them to int (as per Er. Gangaram suggested). Now, you will get the classic mathematical results, the sum of two integral numbers: 3 + 4 = 7, i.e., an integral number.

–1 vote
answered Jun 16, 2025 by Abdullah Shafi (340 points)

                             number1= int(input("Number one is ")) #taking the second number (a)

                     number2= int(input("Number two is ")) #taking the first number (b)

                print(number1 * number2) #taking num1 x num2  that means ab

#This is a program of python 3 programming language

+1 vote
answered Jun 20, 2025 by Vicky Reddy (160 points)
use int(input("take input")).. so it will be considered as an integer otherwise it will be taken as string
+1 vote
answered Jun 22, 2025 by Grid Technical (200 points)
34 is coming because you are not converting your input values to integer datatype, they will be taken as String data type. So it will be like "3"+" 4" . so the answer will be 34

a = int(input("enter no. 1"))

b = int(input("enter no. 2"))

c = (a + b)

print (c)

This will give you 7
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...