Computer Science, asked by Anonymous, 2 months ago

Print this pattern from python
...don't spam...​

Attachments:

Answers

Answered by Anonymous
2

Required python programme::

for row in range (7): # run from 0 to 6

for col in range (5): # run from 0 to 4

if (col==0 or col==4) or (row==3):

print ("* ",end="")

else:

print (end=" ")

print()

‎ ‎ ‎

‎ ‎ ‎

Explanation:

This question can be solved by using if else statement inside nested loop.

>> Firstly print vertical lines of the pattern.

(col==0 or col==4) will print stars in column number 0 and 4. (Remember counting starts from 0 in most of the programming languages).

>> Now print horizontal lines of pattern.

(row==3) will print stars in whole row number 3.

end="" will print the stars in same row.

The end=" " in the body of else statement will print spaces where stars are not allowed to be printed.

>> This will give you the following output:

* *

* *

* *

* * * * *

* *

* *

* *

Similar questions