forked from souravjain540/Basic-Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTriangular_Patterns.py
More file actions
101 lines (87 loc) · 2.78 KB
/
Copy pathTriangular_Patterns.py
File metadata and controls
101 lines (87 loc) · 2.78 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
def righttriangle(z):
nums = [str(i) for i in range(1,z+1)]
for x in range(1, z+1):
print(' '.join(nums[0:x]))
return ''
def isoscelestriangle(x):
nums = [str(i) for i in range(1, 2*x)]
for a in range(x):
num = ''.join(nums[0:((2*a) + 1)])
numspaces = (x - 1 - a)
print(' '*numspaces + num)
return ''
def kite(x):
nums = [str(i) for i in range(1, 2*x)]
for a in range(x):
num = ''.join(nums[0:((2*a) + 1)])
numspaces = (x - 1 - a)
print(' '*numspaces + num)
for b in range(x-1):
c = (2*b) + 2
num = ''.join(nums[0:(len(nums) - c)])
numspaces = int((len(nums) - len(str(num)))/2)
print(' '*numspaces + num)
return ''
def halfkite(z):
nums = [str(i) for i in range(1,z+1)]
for x in range(1, z+1):
print(' '.join(nums[0:x]))
for y in range(1,z):
print(' '.join(nums[0:(len(nums) - y)]))
return ''
def X(z):
nums = [str(i) for i in range(1, 2*z)]
for a in range(z):
num = ''.join(nums[0:(len(nums) - 2*a)])
numspaces = int((len(nums) - len(num))/2)
print(' '*numspaces + num)
for b in range(1, z):
num = ''.join(nums[0:(2*b + 1)])
numspaces = int((len(nums) - len(str(num)))/2)
print(' '*numspaces + num)
return ''
question = ''
while question != 'Exit':
print("""
==========MENU==========
1. Right-angled triangle
2. Isosceles triangle
3. Kite
4. Half Kite
5. X
6. Exit
========================
""")
question = input('Enter the name of the pattern from the above menu that you want to print: ')
if question == 'Right-angled triangle':
n = int(input('Enter the number of lines that you want to print: '))
print('\n')
print(righttriangle(n))
if question == 'Isosceles triangle':
n = int(input('Enter the number of lines that you want to print: '))
if n%2 == 0:
print('\n')
print(isoscelestriangle(n))
else:
print('Enter an even number of lines.')
if question == 'Kite':
n = int(input('Enter the number of lines that you want to print (enter an even number of lines): '))
if n%2 == 0:
print('\n')
print(kite(n))
else:
print('Enter an even number of lines.')
if question == 'Half Kite':
n = int(input('Enter the number of lines that you want to print: '))
print('\n')
print(halfkite(n))
if question == 'X':
n = int(input('Enter the number of lines that you want to print: '))
if n%2 == 0:
print('\n')
print(X(n))
else:
print('Enter an even number of lines.')
if question == 'Exit':
print('\n')
break