0

I don't understand what's wrong with my code

Sololearn asked me to make a simple calculator program that adds numbers together. I don't understand what is wrong with my code n = input("") m = input("") o = n + m print(o) If n is 1 and m is 2, the code returns 12. Why?

1st Sep 2021, 1:45 PM
Ali Mirza
5 Answers
+ 5
Thats because n and m are strings It shoud be n=int(input("")) m=int(input("")) 😊
1st Sep 2021, 1:50 PM
Nadir Nadir
Nadir Nadir - avatar
+ 2
n = input() m = input() o = n + m print(o) Means: string + string n = "1" m = "2" Print(n + m ) Output: 1 2 to input a number u can use int () for example : int(intput()) now the output will be 3
1st Sep 2021, 1:49 PM
Pariket Thakur
Pariket Thakur - avatar
+ 1
If this is relevant, I am doing the Python Core course.
1st Sep 2021, 1:46 PM
Ali Mirza
0
Thanks for the help Nadir Nadir HrCoder
1st Sep 2021, 2:19 PM
Ali Mirza
0
Hi, The values ​​you receive string so first of all you must transform intager this values n =int(input("enter a number" ) ) Like this
3rd Sep 2021, 9:34 AM
Hamza Akburak
Hamza Akburak - avatar