Skip to content

Commit 9666abf

Browse files
committed
Python Program to print pattern of letter K
1 parent 4c180ea commit 9666abf

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

patterns/pattern-k.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
__author__ = 'Avinash'
2+
3+
4+
# Python3 program to print alphabet pattern K
5+
6+
# * *
7+
# * *
8+
# * *
9+
# * *
10+
# * *
11+
# * *
12+
# * *
13+
# * *
14+
# * *
15+
# * *
16+
# * *
17+
# * *
18+
19+
20+
def print_pattern(n):
21+
22+
i = 0
23+
j = n//2
24+
# Outer for loop for number of rows
25+
for rows in range(n):
26+
27+
# Inner for loop columns
28+
for columns in range(n):
29+
30+
# prints first and last column
31+
if columns == 0 or (rows == (columns+(n//3)) and columns > 0):
32+
print("*", end=" ")
33+
elif rows == i and columns == j:
34+
print("*", end=" ")
35+
i = i+1
36+
j = j-1
37+
else:
38+
print(" ", end=" ")
39+
print()
40+
41+
42+
size = int(input("Enter size: \t"))
43+
44+
if size < 8:
45+
print("Enter a size greater than 8")
46+
else:
47+
print_pattern(size)

0 commit comments

Comments
 (0)