0

How do you concatenate pre defined variables?

https://code.sololearn.com/c607GKPSvNRY/?ref=app

13th Jun 2017, 1:50 PM
Zeta Riemann
Zeta Riemann - avatar
8 ответов
0
print(str(x) + foo)
13th Jun 2017, 2:21 PM
LordHill
LordHill - avatar
+ 1
x = 98 foo = input("enter your number ") print(str(x) + " + " + foo) to concatenate with an integer you need to make it a string. so I wrapped it in a str() .. then used + to add another piece. which is a string with 2 spaces and a + sign.. then I used + to add the final piece which is the foo variable. I didn't have to cast it as a str() because input by default is a string.
13th Jun 2017, 2:16 PM
LordHill
LordHill - avatar
+ 1
I tried it. instead of getting x+y, can't the result be xy
13th Jun 2017, 2:19 PM
Zeta Riemann
Zeta Riemann - avatar
0
are you trying to add the 2 numbers and print the result? Or do you want it to actually show the + sign?
13th Jun 2017, 2:08 PM
LordHill
LordHill - avatar
0
I am adding the numbers as if they were strings
13th Jun 2017, 2:11 PM
Zeta Riemann
Zeta Riemann - avatar
0
so if the input was 3 you would want an output of 98+3
13th Jun 2017, 2:12 PM
LordHill
LordHill - avatar
0
so you don't want 98+3 for an output, you would want 983?
13th Jun 2017, 2:21 PM
LordHill
LordHill - avatar
0
thank you. it is correct
13th Jun 2017, 2:24 PM
Zeta Riemann
Zeta Riemann - avatar