0

Simple calculator

Hello, there. I am trying to do a simple calculator with two inputs. I used this code: x = int(input()) y = int(input()) z = x + y print("The result is " + z) But I can't get it right. The result I want is the sum of input 1 and 2. Can someone help me understand? Thanks. :)

28th May 2022, 5:32 PM
Alexandre Leal de Medeiros Martins Moura
Alexandre Leal de Medeiros Martins Moura - avatar
3 Answers
+ 3
Alexandre Leal You cannot concat number with string in python. To do that you need to cast number with str function: print ("The result is " + str(z))
29th May 2022, 6:12 AM
A͢J
A͢J - avatar
+ 2
You should do it like this.... x = int(input()) y = int(input()) z = x + y print("The result is ", z) Don't use + in print. Use , instead of +. + is used for concatenation
28th May 2022, 5:49 PM
Rakshika Singh
Rakshika Singh - avatar
+ 1
Thank you, man. I didn't notice that. :D
28th May 2022, 5:51 PM
Alexandre Leal de Medeiros Martins Moura
Alexandre Leal de Medeiros Martins Moura - avatar