Increment AND concatenate a variable in Python

  Kiến thức lập trình

I want to increment a variable in a loop to get x1, x2, x3, etc.
your textloop = 0
your textWhile loop < 4
your textxn = something, something else, something else again..
your textn += 1
your textloop += 1
At the end, I want to have x1, x2, x3 all equal to different things

This is not working. This appears to be a combination of incrementing **AND ** concatenation of a variable at the same time. Any hints?

I’ve tried:
globalizing xn, x1, x2, x3
concatenating strings and converting to integer, xn = int(str(x) + str(n)).
concat(x, n)
xnew = x + n

Nothing seems to be working. At the end, x1, x2 and x3 are all zero

LEAVE A COMMENT