You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 10_Loops/README.md
+114-2Lines changed: 114 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Python Loops -
1
+
# Python Loops
2
2
3
3
Loops in Python are used to execute a block of code multiple times. Instead of writing the same code repeatedly, loops help automate repetitive tasks. Python provides two main types of loops:
4
4
## There are two types of loops in Python
@@ -175,6 +175,118 @@ Write a `while` loop that finds and prints the first multiple of 7 greater than
175
175
Write a program that uses a `for` loop to count the number of vowels in a given string.
176
176
177
177
178
+
### 6. Prime Numbers in a Range
179
+
180
+
Input: Start = 10, End = 50
181
+
Task: Use loops to print all the prime numbers in the given range.
182
+
Output:
183
+
184
+
```
185
+
11 13 17 19 23 29 31 37 41 43 47
186
+
```
187
+
188
+
189
+
### 7. Fibonacci Series (n terms)
190
+
191
+
Input: n = 10
192
+
Task: Use loops to generate the Fibonacci series (0, 1, 1, 2, 3, 5, ...).
193
+
Output:
194
+
195
+
```
196
+
0 1 1 2 3 5 8 13 21 34
197
+
```
198
+
199
+
200
+
### 8. Palindrome Number Check (Without Converting to String)
201
+
202
+
Input: 121
203
+
Task: Use a while loop to reverse the number and check if it is a palindrome.
204
+
Output:
205
+
206
+
```
207
+
121 is a palindrome number
208
+
```
209
+
210
+
211
+
### 9. Pattern Printing — Pyramid
212
+
213
+
Input: n = 5
214
+
Output:
215
+
216
+
```
217
+
*
218
+
***
219
+
*****
220
+
*******
221
+
*********
222
+
```
223
+
224
+
Task: Use nested for loops to print a center-aligned pyramid pattern.
225
+
226
+
227
+
### 10. Armstrong Number Check (n digits)
228
+
229
+
Input: 153
230
+
Task: Check whether the number is an Armstrong number or not.
231
+
(Armstrong: 13 +たす 53 +たす 33 =わ 153)
232
+
Output:
233
+
234
+
```
235
+
153 is an Armstrong number
236
+
```
237
+
238
+
239
+
### 11. Factorial Without Using math Module
240
+
241
+
Input: n = 10
242
+
Task: Use a for or while loop to calculate the factorial of the number without using the math module.
243
+
244
+
245
+
### 7. Multiplication Table — 1 to 10
246
+
247
+
Task: Use nested loops to print the multiplication tables from 1 to 10.
248
+
Example:
249
+
250
+
```
251
+
1 x 1 = 1
252
+
1 x 2 = 2
253
+
...
254
+
10 x 10 = 100
255
+
```
256
+
257
+
258
+
### 12. Sum of Digits Until Single Digit
259
+
260
+
Input: 9875
261
+
Task: Use a while loop to repeatedly sum the digits of the number until you get a single digit.
262
+
(9+8+7+5 = 29 → 2+9 = 11 → 1+1 = 2)
263
+
Output:
264
+
265
+
```
266
+
2
267
+
```
268
+
269
+
270
+
### 13. Reverse a String Without Using Slice or reversed()
271
+
272
+
Input: Dhruba
273
+
Task: Use a loop to reverse the string.
274
+
Output:
275
+
276
+
```
277
+
aburhD
278
+
```
279
+
280
+
281
+
### 13. Find GCD Using Loops (Without math.gcd)
282
+
283
+
Input: num1 = 56, num2 = 98
284
+
Task: Use for or while loops to find the GCD (Greatest Common Divisor) of the two numbers.
285
+
Output:
286
+
287
+
```
288
+
GCD = 14
289
+
```
178
290
179
291
## Conclusion
180
292
- Use `for` loops when iterating over a sequence (lists, strings, tuples, etc.).
@@ -183,4 +295,4 @@ Write a program that uses a `for` loop to count the number of vowels in a given
183
295
- Use `continue` to skip an iteration and move to the next one.
184
296
- Use `else` with loops for additional execution after the loop finishes normally.
0 commit comments