Computer Science, asked by goelayush2003, 1 year ago

How to draw these patterns in Python!?

Attachments:

Answers

Answered by sswaraj04
1

Answer:

for i in range(1,4):

   for j in range(i,3):

       print(end=" ")

   for k in range(0,i):

       print("*",end=" ")

   print("\n")

for i in range(1,3):

   for j in range(0,i):

       print(end=" ")

   for k in range(i,3):

       print("*",end=" ")

   print("\n")

   

print("New pattern")

for i in range(1,4):

   for j in range(0,i):

       print("*",end=" ")

   print("\n")

for i in range(1,3):

   for j in range(i,3):

       print("*",end=" ")

   print("\n")

Explanation:

For your help I'm just posting answers of a) and b)

Now try doing c) and d) on own..

Basically logic behind program is using loops properly..

Outer loop is always for no. of rows

for first pattern there are 5 rows but after 3 rows patern reverses

so, running loop twice once for 3 time(1,4) and again for 2 time..(1,3)

now, it got 2 elements spaces and star(*)

2 inner loops for both element

first for spaces--how many spaces we want in each line so adjust

ex-first line 2 second line 1 and third line 0 so ->(i,3) gives exact value of spcaes for each lines

and then adjust loops for no. of stars

Now b) is easy just remove space elements from part a)

For part c) count no of spaces in each line and it has inner spaces so,it got 3 elements..

Try to implement it

Hope it helps :-)

Ask any furthur doubt......................

Similar questions