Formatting a list of numbers using for loops in python -
so i've got homework assignment i'm having trouble with.
we're supposed use nested loops display set of numbers in variety of different ways. need 3 out of 4 of following patterns, , know how make 1.
pattern a
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
pattern b
1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
pattern c
1 2 1 3 2 1 4 3 2 1 5 4 3 2 1
pattern d
1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
(i don't know why c , d won't display right, should have idea)
i've got following code make pattern a:
for x in range(5): y in range(1, x + 2): print(y, end = '\r') print()
any appreciated!
what see changing part c , d? there's numbers change along initial space between first number, right? implies need keep track of # of spaces in loop. , b, if can piece algorithm 1, can other. hint: what's initial starting point each pattern , how change?
Comments
Post a Comment