0

a = ['*','#','$'] b = [1,4,7]

How can I make use of the above lists and loop to print the pattern with the required number of rows? Here are 2 examples if the input is 5 and 10 respectively. Do not need to print the bracket on each line. Thanks.


Number of rows: 5

(*)

(####)

($$$$$$$)

(*)

(####)


Number of rows: 10

(*)

(####)

($$$$$$$)

(*)

(####)

($$$$$$$)

(*)

(####)

($$$$$$$)

(*)

  • Can you include what code you have already tried and where you are getting stuck? – Tim Mar 28 '20 at 10:52

2 Answers2

1

You can use the modulus operator (%) to iterate through a and b and repeat from the beginning of the list.

a = ['*', '#', '$']
b = [1, 4, 7]
rows = int(input('>>> '))
print('\n\n'.join(f'({a[i % len(a)] * b[i % len(b)]})' for i in range(rows)))
alec
  • 5,799
  • 1
  • 7
  • 20
0

You can multiply A* B and then shift A and B by 1 per Loop Iteration

Easy to implement user input

a = ['*','#','$']
b=[1,4,7]
b.reverse()
b = b[-1:] + b[:-1]

print(b)

for x in range(5):
  print(a[0]*b[0])
  a = a[-1:] + a[:-1]
  b = b[-1:] + b[:-1]
azuldev
  • 570
  • 6
  • 10