0

Multiple variables??

X = 5 Y = X+3 Y = int(str(y)+”2”) Print(y) Output: 82 Had to get a hint for the answer on this, can understand from the answer how the output has come to 82 but can’t figure out why str(y) has multiplied 8 by 10?

14th Feb 2021, 6:22 PM
Jordan Bullus
Jordan Bullus - avatar
6 Answers
0
Jordan The value of variable Y is 8, which you typecasted in the same variable and then added 2 to 8 which is now a string and as Angelo said strings are concatenated not added, so: '8'+'2' = 82
15th Feb 2021, 2:01 AM
∆BH∆Y
∆BH∆Y - avatar
+ 2
Where does the 7 come from? Btw remember that "ab" + "cd" == "abcd" So "8" + "2" == "82"
14th Feb 2021, 6:30 PM
Angelo
Angelo - avatar
+ 1
It's not 8, it's "8"
14th Feb 2021, 6:35 PM
Angelo
Angelo - avatar
0
i meant to type 8 my bad
14th Feb 2021, 6:32 PM
Jordan Bullus
Jordan Bullus - avatar
0
sorry trying to message you i think youve sorted it for me, is str(y) just 8 then?
14th Feb 2021, 6:34 PM
Jordan Bullus
Jordan Bullus - avatar
0
One tip: No two variables should be same in a program
15th Feb 2021, 2:03 AM
∆BH∆Y
∆BH∆Y - avatar