python - How to make integer patterns? -
i want build sequence pattern, example have numbers 1
, 2
, 3
.
1
first pattern, 2
second, , 3
third.
# assign patterns. first = 1 second = 2 third = 3 # make loop x in xrange(1, 100): print(second)
this print second, want print number after every 2
integers.
so example:
1 2 - pattern 2 3 4 - pattern 2 5 6 - pattern 2 7 ...
how achieve sequence? can make integer patterns in loop, such integer 2
, after every 2
integers prints pattern2 integer returned.
xrange
has step parameter. see documentation.
for x in xrange(1, 100, 2): print(second)
to print pattern 1, 2 , 3 successively:
patterns = [first, second, third] x in xrange(1, 100): print(patterns[x % 3])
to print third:
for x in xrange(1, 100): if x % 3 == 0: print(third)
Comments
Post a Comment