How to print pattern P using Python
#code:
for i in range (7):
for j in range (6):
if (j in {0,1,2,3,4} and i==0 or j==0) or (i in {1,2} and j==5) or (j in {0,1,2,3,4} and i==3):
print("*",end=' ')
else:
print(" ",end=' ')
print()
Explanation:
for i in range (7):
for j in range (6):
This code is use to define the rows and column
here for i in range (7): This code means that the loop will runs 7 times specially for the rows.
for j in range (6): This code means that the loop will runs 6 times specially for the columns.
in the if statement we are going to provide the condition to print virtical lines in column 0.
#code:1
for i in range (7):
for j in range (6):
if (j in {0,1,2,3,4} and i==0 or j==0):
print("*",end=' ')
output:
★★★★★
★
★
★
★
★
★
using the #code:1 we can print the above pattern
now using or operator we are going to print some more lines to our pattern .. have a look
or (i in {1,2} and j==5)
now we are going to add this piece of code to #code:1 to see the output.
#code:1
for i in range (7):
for j in range (6):
if (j in {0,1,2,3,4} and i==0 or j==0)or (i in {1,2} and j==5)
print("*",end=' ')
output:
★★★★★
★ ★
★ ★
★
★
★
★
after inserting the red line into the #code:1 we can print the above pattern .
now using or operator we are going to print some more lines to our pattern .. have a look
or (j in {0,1,2,3,4} and i==3):
now we are going to add this piece of code to #code:1 to see the output.
#code:1
for i in range (7):
for j in range (6):
if (j in {0,1,2,3,4} and i==0 or j==0)or (i in {1,2} and j==5) or (j in {0,1,2,3,4} and i==3):
print("*",end=' ')
here's guys our code is completed so it will printd the whole pattern P.
output:
★★★★★
★ ★
★ ★
★★★★★
★
★
★
for web developement tutorial please click on youtube icon.
Post a Comment