Search code examples
python-3.xloopsfor-looprangeincrement

how can I increment the first number in a range?


Learning python and I need to figure out to to increase the first number in a range?


measures = 4
beats_per_measures = 4
beats = 0

for i in range(0, measures):
    for beats in range(1 , beats_per_measure + 1):
        print(beats)

so I can get the output to print the beats per measure the number of measures. BOOm. but now I need to increase the first beat by one every measure and I know it's easier than I am making it. I have preformed multiple searches online and I am guessing that because I don't know how to read the complex answers or I don't know how to phrase what I am trying to do is why I have not found an answer yet.


Solution

  • Is this what you need?

    I thought you needed each set (1,2,3,4) in the same line.

    measures = 4
    beats_per_measure = 4
    
    for i in range(measures):
        for var_beat in range(beats_per_measure):
            var_beat = str(1 + var_beat)
            fixed_beat = ' '.join([ str(1+f) for f in range(beats_per_measure)[1:]])
            print(var_beat + ' ' + fixed_beat)
    

    I am a little bit confused with your "so on" in your comment.