-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathpattern_printer.py
More file actions
103 lines (85 loc) · 2.09 KB
/
Copy pathpattern_printer.py
File metadata and controls
103 lines (85 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# triangle function to print triangle pattern
def triangle(rows):
for i in range(1, rows + 1):
for j in range(i, 0, -1):
print("*", end=' ')
print("")
# square function
def square(rows):
for i in range(1, rows + 1):
for j in range(1, rows + 1):
if j <= i:
print("*", end=' ')
else:
print("*", end=' ')
print()
# sand glass function
def sandGlass(rows):
i = 0
while i <= rows - 1:
j = 0
while j < i:
# display space
print('', end=' ')
j += 1
k = i
while k <= rows - 1:
print('*', end=' ')
k += 1
print()
i += 1
i = rows - 1
while i >= 0:
j = 0
while j < i:
print('', end=' ')
j += 1
k = i
while k <= rows - 1:
print('*', end=' ')
k += 1
print('')
i -= 1
# pant style function
def pantStyle(rows):
print("*" * rows, end="\n")
i = (rows // 2) - 1
j = 2
while i != 0:
while j <= (rows - 2):
print("*" * i, end="")
print("_" * j, end="")
print("*" * i, end="\n")
i = i - 1
j = j + 2
def diamond(rows):
k = 2 * rows - 2
for i in range(0, rows):
for j in range(0, k):
print(end=" ")
k = k - 1
for j in range(0, i + 1):
print("* ", end="")
print("")
k = rows - 2
for i in range(rows, -1, -1):
for j in range(k, 0, -1):
print(end=" ")
k = k + 1
for j in range(0, i + 1):
print("* ", end="")
print("")
print("Welcome to the pattern printer!\n")
print("1. Triangle\n2. Square\n3. Sandglass\n4. Pant Style\n5. Diamond\n")
shape = int(input("Select the shape you would like to print: "))
rows = int(input("Enter number of rows: "))
if shape == 1:
triangle(rows)
if shape == 2:
square(rows)
if shape == 3:
sandGlass(rows)
if shape == 4:
pantStyle(rows)
if shape == 5:
diamond(rows)