num1 = input("First number : ")
num2 = input("Second number : ")
sum = num1 + num2
print (sum)
#output
#First number : 1
#Second number : 2
#12
Asked
Active
Viewed 228 times
-3

Nilesh Pathare
- 1
- 1
-
becuase you taking input as string so in string concaticnation 1+ 2=12 – ravishankar chavare Mar 05 '19 at 09:55
2 Answers
0
You Should try Type conversion
num1 = int(input("First number : "))
num2 = int(input("Second number : "))
sum = num1 + num2
print (sum)

ravishankar chavare
- 503
- 3
- 14
0
Problem is the input will be considered as string as per your program, you have to do a little modification in your program. Just add int before input and it'll do the work.
num1 = int(input("Enter number one: "))
num2 = int(input("Enter number two: "))
print(num1+num2)
There is no error, the output is just concatenated num1 and num2, you need integers to perform addition.
You can understand it clearly in interactive shell
>>>"1"+"2" #your code is doing the same
>>>12
>>>1+2 #this is what you need to do
>>>3

Damian Wayne
- 1
- 1
- 3
-
Nice explanation. Maybe it would help to add some code snippet when you said `Just add int before input and it'll do the work` having `num1 = int(input("First number : "))` could make your answer clearer – Al-un Mar 05 '19 at 10:31
-
1