How to increment x1 to x10 in python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to increment x1 to x10 in python?

I want to increment x1 to x10 in python. The expected output should be X1 X2 X3 . . . X10

11th Jan 2021, 6:45 PM
Karzan
4 Answers
+ 5
You can use a loop and increment a variable, which can be converted to a string and add to X.
11th Jan 2021, 6:48 PM
JaScript
JaScript - avatar
+ 4
Hint: You can easily use a for loop to iterate on a range of 1 to 10. While iterating on the range, use the str() function to convert each number to string. Then print "X" added to the string form of the number.
11th Jan 2021, 6:49 PM
XXX
XXX - avatar
+ 2
Please provide link to your attempt.
11th Jan 2021, 7:19 PM
JaScript
JaScript - avatar
0
Solved it using string and integer. I remember was an easier way to do this. All in one line instead of using if else statement. I used if else statement because in reality I wanted to increment A001 to A100. So I used if else statement. If you have a better way to get this done to save on time complexity please share.
11th Jan 2021, 7:01 PM
Karzan