-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractice_10.py
More file actions
55 lines (50 loc) · 1.49 KB
/
Practice_10.py
File metadata and controls
55 lines (50 loc) · 1.49 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
'''' I am using two functions (Practice_06 and Practice_10) to print the Diamond
but there is some change in my last function inverted Pyramid as you move forward
you will be able to understand how i Do it '''
def generate_pyramid(n):
"""
Function to return a pyramid pattern of '*' of side n as a list of strings.
Parameters:
n (int): The number of rows in the pyramid.
Returns:
list: A list of strings where each string represents a row of the pyramid.
"""
k=1
i=1
while(i<=n):
b=1 #it will count the space
while(b<=5-i):
print(" ",end='')
b+=1
j=1 # print *
while(j<=k):
print("*",end='')
j+=1
k=k+2
print()
i+=1
def generate_inverted_pyramid(n):
"""
Function to return an inverted pyramid pattern of '*' of side n as a list of strings.
Parameters:
n (int): The number of rows in the inverted pyramid.
Returns:
list: A list of strings where each string represents a row of the inverted pyramid.
"""
k = 2 * n - 3 # start from second last row star count
i = 1
while i <= n - 1:
b = 1
while b <= i:
print(" ", end='')
b += 1
j = 1
while j <= k:
print("*", end='')
j += 1
k = k - 2
print()
i += 1
row=int(input("Enter no. of rows in Inverted Diamond;\n"))
generate_pyramid(row)
generate_inverted_pyramid(row)