-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatternProgramming.py
More file actions
76 lines (59 loc) · 1.27 KB
/
Copy pathPatternProgramming.py
File metadata and controls
76 lines (59 loc) · 1.27 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
rowNum = 5
# The number of asterisk in each row equals to the row number
# Drawing 1 row of stars(5 stars)
for i in range(5): # For loop approach
print("*", end=" ")
print("\r") # go to the next line
def Pyramid(rowNum):
for i in range(1, rowNum + 1, 1):
print("*" * i) # String multiplication approach
# Reverse the triangle
for i in range(rowNum - 1, 0, -1):
print("*" * i)
def NumberPyramid(rowNum):
"""
e.g. rowNum = 5
1
22
3 3 3
4 4 4 4
5 5 5 5 5
"""
for i in range(1, rowNum + 1, 1):
print((str(i) + " ") * i)
"""
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
"""
def NumPyramid2(rowNum):
for j in range(2, rowNum + 2, 1):
for i in range(1, j, 1):
print(i, end=" ")
print("\r")
"""
Multiplication table pattern
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
...
"""
print(1 * 1, end = " ")
print("\r")
print(2 * 1, end = " ")
print(2 * 2, end = " ")
print("\r")
print(3 * 1, end = " ")
print(3 * 2, end = " ")
print(3 * 3, end = " ")
print("\r")
for j in range(1, rowNum + 1, 1):
# For each row repeat column times (row number)
for i in range(1, j + 1, 1):
print(i * j, end=" ")
print("\r")
# first step, identify numbers that are changing, then replace it with a variable