Multiple variables?? | SoloLearn: Learn to code for FREE!

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?

2/14/2021 6:22:34 PM

Jordan Bullus

6 Answers

New Answer

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

+2

Where does the 7 come from? Btw remember that "ab" + "cd" == "abcd" So "8" + "2" == "82"

+1

It's not 8, it's "8"

0

i meant to type 8 my bad

0

sorry trying to message you i think youve sorted it for me, is str(y) just 8 then?

0

One tip: No two variables should be same in a program