-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assignment solution of coding ninjas
179 lines (139 loc) · 2.36 KB
/
Assignment solution of coding ninjas
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
Number Pattern 1
Print the following pattern for the given N number of rows.
Pattern for N = 4
1
11
111
1111
Input format :
Integer N (Total no. of rows)
Output format :
Pattern in N lines
Sample Input :
5
Sample Output :
1
11
111
1111
11111
___________________________________
solution for this code is
n = int(input())
i =1
while i <= n:
j = 1
while j <= i:
print('1', end = "")
j = j + 1
print()
i = i + 1
___________________________________
Number Pattern 3
Print the following pattern for the given N number of rows.
Pattern for N = 4
1
11
121
1221
Input format :
Integer N (Total no. of rows)
Output format :
Pattern in N lines
Sample Input :
5
Sample Output :
1
11
121
1221
12221
___________________________________
solution for this code
def print_pattern(n):
for i in range(1, n + 1):
for j in range(1, i + 1):
if j == 1 or j == i:
print(1, end='')
else:
print(2, end='')
print()
# Read the input
n = int(input())
# Call the function to print the pattern
print_pattern(n)
_____________________________________
Number Pattern
Print the following pattern for the given N number of rows.
Pattern for N = 4
1234
123
12
1
Input format :
Integer N (Total no. of rows)
Output format :
Pattern in N lines
Sample Input :
5
Sample Output :
12345
1234
123
12
1
_____________________________________
solution for this code
def print_pattern(n):
for i in range(n, 0, -1):
for j in range(1, i + 1):
print(j, end='')
print()
# Read the input
n = int(input())
# Call the function to print the pattern
print_pattern(n)
______________________________________
Alpha Pattern
Print the following pattern for the given N number of rows.
Pattern for N = 3
A
BB
CCC
Input format :
Integer N (Total no. of rows)
Output format :
Pattern in N lines
Constraints
0 <= N <= 26
Sample Input 1:
7
Sample Output 1:
A
BB
CCC
DDDD
EEEEE
FFFFFF
GGGGGGG
Sample Input 2:
6
Sample Output 2:
A
BB
CCC
DDDD
EEEEE
FFFFFF
______________________________________________
solution for this code
def print_pattern(n):
for i in range(n):
for j in range(i + 1):
print(chr(ord('A') + i), end='')
print()
# Read the input
n = int(input())
# Call the function to print the pattern
print_pattern(n)
______________________________________________