What is the difference between this 2 python calculations | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the difference between this 2 python calculations

Question 1 a = input("a="). .... value entered 5 b = input("b="). .... value entered 6 c = int(a+b) print (c) answer was 56 I EXPECTED 11 QUESTION 2. a = input("a="). .... value entered 5 b = input("b="). .... value entered 6 c = int(a) + int(b) print (c) answer was 11 which is what I expected why are the answers different?

22nd Apr 2020, 11:45 AM
Ojo Sampson
Ojo Sampson - avatar
3 Answers
+ 1
thanks guys
22nd Apr 2020, 11:56 AM
Ojo Sampson
Ojo Sampson - avatar
0
So invariably... the '+' simply place the 2 figures next to each other?
22nd Apr 2020, 11:51 AM
Ojo Sampson
Ojo Sampson - avatar
0
Input returns string ,so in first 5 was "5" and 6 was "6" so adding two strings will give 56 and in second method you converted string type to int so it was 11
22nd Apr 2020, 11:51 AM
Abhay
Abhay - avatar