How to create expression that returns 1,12,123,1234 in Python

1

I'm learning the basics of python and I came across an exercise where I have to build the following sequence:

1   
12  
123  
1234  
12345  
123456  
1234567  
12345678  
123456789 

I think it's a simple thing to do, but can anyone help me?

    
asked by anonymous 29.09.2015 / 16:39

2 answers

3

The code is very simple:

st = ''
for i in range(1, 10):
    st += str(i)
    print st

Test online: link .

    
29.09.2015 / 16:57
0

You can use a loop that has the minimum value and rotate as long as it is smaller and / or equal to the maximum value and print the value before incrementing.

    
30.09.2015 / 04:02