+ 1

I don't understand how 82 is the solution to this problem. please explain. thanks so much.

x = 5 >>> y = x + 3 >>> y = int(str(y) + "2") >>> print(y)

26th May 2020, 1:49 PM
Sandra Smith
Sandra Smith - avatar
6 odpowiedzi
+ 5
y = 5+3 = 8 str(y) = "8" "8" + "2" = "82" // string concatenation int("82") = 82
26th May 2020, 1:54 PM
Avinesh
Avinesh - avatar
+ 1
Sandra Smith you have explicitly converted y=int(str(y)+"2") to integer type, which will convert the parameter. Before that, python accept everything as String. Try removing int par and print(y). You could also use type keyword to find the datatype of y, like, print(type(y)). Thank you
26th May 2020, 2:12 PM
Prantik Sarkar
Prantik Sarkar - avatar
0
You've converted y to a string so now you're no longer dealing with numbers. They look like numbers but are being treated the same as a string. For example: "Hello "+"World" = Hello World "8" + "2" = 82
26th May 2020, 4:35 PM
Olivia
Olivia - avatar
0
Thank you all so, so very much!
28th May 2020, 10:21 PM
Sandra Smith
Sandra Smith - avatar