Computer Science, asked by singhdivyansh0911, 3 days ago

print the pattern in Python.
Wrong answers will be reported.​

Attachments:

Answers

Answered by anindyaadhikari13
2

Solution:

The given co‎de is written in Python.

1) For Pattern H

r, c = 5, 4

for i in range(r):

for j in range(c):

 if j == 0 or j == c - 1 or i == r // 2:

  print('* ', end = '')

 else:

  print('  ', end = '')

print()

2) For Pattern E

r, c = 5, 4

for i in range(r):

   for j in range(c):

       if i == 0 or i == r - 1 or j == 0 or i == c // 2 and j < c - 1:

           print('* ', end = '')

   print()

3) For Pattern L

r, c = 5, 4

for i in range(r):

for j in range(c):

 if i == r - 1 or j == 0:

  print('* ', end = '')

print()

4) For Pattern I

r = c = 5

for i in range(r):

for j in range(c):

 if i == 0 or i == r - 1 or j == c // 2:

  print('* ', end = '')

 else:

  print('  ', end = '')

print()

5) For Square Pattern.

r = c = 5

for i in range(r):

for j in range(c):

 if i == 0 or i == r - 1 or j == 0 or j == c - 1:

  print('* ', end = '')

 else:

  print('  ', end = '')

print()

Refer to the attachment for output.

Attachments:
Similar questions