0
How do you concatenate pre defined variables?
8 Respostas
0
print(str(x) + foo)
+ 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.
+ 1
I tried it. instead of getting x+y, can't the result be xy
0
are you trying to add the 2 numbers and print the result? Or do you want it to actually show the + sign?
0
I am adding the numbers as if they were strings
0
so if the input was 3 you would want an output of
98+3
0
so you don't want 98+3 for an output, you would want 983?
0
thank you. it is correct