-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path305.py
More file actions
109 lines (74 loc) · 1.95 KB
/
305.py
File metadata and controls
109 lines (74 loc) · 1.95 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
104
105
106
# 3.5 Write a program that prints the following patterns separately, one below the other each pat- tern separated from the next by one blank line. Use for loops to generate the patterns. All asterisks (*) should be printed by a single statement of the form
# print '*',
# (which causes the asterisks to print side by side separated by a space). (Hint: The last two patterns require that each line begin with an appropriate number of blanks.) Extra credit: Combine your code from the four separate problems into a single program that prints all four patterns side by side by making clever use of nested for loops. For all parts of this program—minimize the numbers of asterisks and spaces and the number of statements that print these characters.
# a) Half pyramid
# b)Left Half Pyramid
# c) Inverted half pyramid d)Full inverted Pyramid
rows = 5
"""
#a) Half pyramid
*
* *
* * *
* * * *
* * * * *
"""
print("a) Half pyramid")
for i in range(rows):
for j in range(i+1):
print("* ", end=" ")
print("\n")
"""
#b) Left Half Pyramid
*
* *
* * *
* * * *
* * * * *
"""
print("b)Left Half Pyramid")
for i in range(rows):
loop = rows-i
j = 1
while j < loop:
print(end=" ")
j += 1
k = 0
while k <= i:
print("* ", end=" ")
k += 1
print("\n")
"""
#c) Inverted half pyramid
* * * * *
* * * *
* * *
* *
*
"""
print("c) Inverted half pyramid")
for i in range(rows):
loop = rows - i
for j in range(loop):
print("* ", end=" ")
print("\n")
"""
#d) Full inverted Pyramid
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
"""
print("d) Full inverted Pyramid")
rows = 9
loop = rows
for i in range(rows):
k = 0
for j in range(loop):
while(k<i):
print(end=" ")
k = k+1
print("* ", end=" ")
loop = loop - 2
print("\n")