0% found this document useful (0 votes)
33 views3 pages

Pattern

This document contains Python code that prints various star patterns by using nested for loops. It includes patterns that print stars in ascending and descending order, patterns with increasing or decreasing spacing between stars, and patterns that print numbers or characters instead of stars. The code demonstrates different techniques for printing pyramid-shaped patterns through iterative processes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

Pattern

This document contains Python code that prints various star patterns by using nested for loops. It includes patterns that print stars in ascending and descending order, patterns with increasing or decreasing spacing between stars, and patterns that print numbers or characters instead of stars. The code demonstrates different techniques for printing pyramid-shaped patterns through iterative processes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1 # -*- coding: utf-8 -*-

2 """nishiPatternProgram.ipynb
3
4 Automatically generated by Colaboratory.
5
6 Original file is located at
7 https://colab.research.google.com/drive/1kqn6IhHh8wp6vIyIkSVxtLyLfq6wKGfg
8 """
9
10 n = 5
11
12 for i in range(0, n):
13 for j in range(0, i+1):
14 print("* ",end="")
15 print("\n")
16
17 n = 5
18
19 for i in range(n, 0,-1):
20 for j in range(0, i):
21 print("* ",end="")
22 print("\n")
23
24 n = 5
25 k = 2*n - 2
26 for i in range(0, n):
27 for j in range(0, k):
28 print(end=" ")
29 k = k - 2
30 for j in range(0, i+1):
31 # printing stars
32 print("* ", end="")
33 print("\r")
34
35 # Program to print One More Star Pattern Pyramid
36
37 rows = 3
38 for i in range (0, rows):
39 for j in range(0, i + 1):
40 print("* ", end='')
41 print("\r")
42 for i in range (rows, 0, -1):
43 for j in range(0, i -1):
44 print("* ", end='')
45 print("\r")
46
47 num_rows = 4
48 k=0
49 for i in range(1, num_rows + 1):
50 for j in range (1, (num_rows - i) + 1):
51 print(end = " ")
52 while k != (2 * i - 1):
53 print("*", end = "")
54 k = k + 1
55 k = 0
56 print()
57
58 '''k = 2
59 m = 1
60 for i in range(1, num_rows):
61 for j in range (1, k):
62 print(end = " ")
63 k = k + 1
64 while m <= (2 * (num_rows - i) - 1):
65 print("*", end = "")
66 m = m + 1
67 m = 1
68 print()'''
69
70 n = 5
71 num = 1
72
73 # outer loop to handle number of rows
74 for i in range(0, n):
75 #num = 1
76 for j in range(0, i+1):
77 print(i+1, end=" ")
78 num = num + 1
79 # ending line after each row
80 print("\r")
81
82 n = 5
83 num = 1
84
85 # outer loop to handle number of rows
86 for i in range(0, n):
87 #num = 1
88 for j in range(0, i+1):
89 print(j+1, end=" ")
90 num = num + 1
91 # ending line after each row
92 print("\r")
93
94 n = 5
95 num = 1
96 # outer loop to handle number of rows
97 for i in range(0, n):
98 for j in range(0, i+1):
99 print(num, end=" ")
100 num = num + 1
101 print("\r")
102
103 print("Full Pyramid Pattern of Stars (*): ")
104 for i in range(5):
105 for s in range(-6, -i):
106 print(" ", end="")
107 for j in range(i+1):
108 print(" *", end="")
109 print()
110
111 n = 5
112 num = 65
113 for i in range(0, n):
114 for j in range(0, i+1):
115 ch = chr(num)
116 print(ch, end=" ")
117 num = num + 1
118 # ending line after each row
119 print("\r")
120
121 n = 5
122 num = 65
123 for i in range(0, n):
124 for j in range(0, i+1):
125 ch = chr(num)
126 print(ch, end=" ")
127 num = num + 1
128 print("\r")
129
130 n = 5
131 num = 1
132 for i in range(0, n):
133 num = 1
134 for j in range(0, i+1):
135 print(num, end=" ")
136 num = num + 1
137 print("\r")
138
139 n = 5
140
141 for i in range(n, 0, -1):
142 num = 1
143 for j in range(0, i):
144 print(num, end=" ")
145 num = num + 1
146 print("\r")
147
148 n = 5
149 k = n - 1
150 for i in range(0, n):
151 for j in range(0, k):
152 print(end=" ")
153 k = k - 1
154 for j in range(0, i+1):
155 print("* ", end="")
156 print("\r")
157
158 n = 5
159
160 for i in range(n, 0, -1):
161 num = i
162 for j in range(0, i):
163 print(num, end=" ")
164 num = num - 1
165 print("\r")
166
167 rows = 5
168 # rows value assign to n variable
169 n = rows
170 # Download reversed loop
171 for i in range(rows, 0, -1):
172 for j in range(0, i):
173 # this will print the same number
174 print(" *", end=' ')
175 print()

You might also like