forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhalf triangle pattern.py
More file actions
70 lines (52 loc) · 1.37 KB
/
Copy pathhalf triangle pattern.py
File metadata and controls
70 lines (52 loc) · 1.37 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
# (upper half - repeat)
# 1
# 22
# 333
# (upper half - incremental)
# 1
# 12
# 123
# (lower half - incremental)
# 123
# 12
# 1
# (lower half - repeat)
# 333
# 22
# 1
def main():
lines = int(input("Enter no.of lines: "))
pattern = input("i: increment or r:repeat pattern: ").lower()
part = input("u: upper part or l: lower part: ").lower()
match pattern:
case "i":
if part == "u":
upper_half_incremental_pattern(lines)
else:
lower_half_incremental_pattern(lines)
case "r":
if part == "u":
upper_half_repeat_pattern(lines)
else:
lower_half_repeat_pattern(lines)
case _:
print("Invalid input")
exit(0)
def upper_half_repeat_pattern(lines=5):
for column in range(1, (lines + 1)):
print(f"{str(column) * column}")
def lower_half_repeat_pattern(lines=5):
for length in range(lines, 0, -1):
print(f"{str(length) * length}")
def upper_half_incremental_pattern(lines=5):
const = ""
for column in range(1, (lines + 1)):
const += str(column)
print(const)
def lower_half_incremental_pattern(lines=5):
for row_length in range(lines, 0, -1):
for x in range(1, row_length + 1):
print(x, end="")
print()
if __name__ == "__main__":
main()