|
11 | 11 | <a href="https://www.linkedin.com/in/asabeneh/" target="_blank">Asabeneh Yetayeh</a><br> |
12 | 12 | <small> Second Edition: July, 2021</small> |
13 | 13 | </sub> |
| 14 | + |
14 | 15 | </div> |
15 | 16 |
|
16 | 17 | [<< Day 9](../09_Day_Conditionals/09_conditionals.md) | [Day 11 >>](../11_Day_Functions/11_functions.md) |
|
85 | 86 |
|
86 | 87 | The above loop condition will be false when count is 5 and the loop stops, and execution starts the else statement. As a result 5 will be printed. |
87 | 88 |
|
88 | | - |
89 | 89 | ### Break and Continue - Part 1 |
90 | 90 |
|
91 | 91 | - Break: We use break when we like to get out of or stop the loop. |
@@ -284,15 +284,15 @@ for number in numbers: |
284 | 284 | print('outside the loop') |
285 | 285 | ``` |
286 | 286 |
|
287 | | -In the example above, if the number equals 3, the step *after* the condition (but inside the loop) is skipped and the execution of the loop continues if there are any iterations left. |
| 287 | +In the example above, if the number equals 3, the step _after_ the condition (but inside the loop) is skipped and the execution of the loop continues if there are any iterations left. |
288 | 288 |
|
289 | 289 | ### The Range Function |
290 | 290 |
|
291 | | -The _range()_ function is used list of numbers. The _range(start, end, step)_ takes three parameters: starting, ending and increment. By default it starts from 0 and the increment is 1. The range sequence needs at least 1 argument (end). |
| 291 | +The _range()_ function is used to return a list of numbers. The _range(start, end, step)_ takes three parameters: starting, ending and increment. By default it starts from 0 and the increment is 1. The range sequence needs at least 1 argument (end). |
292 | 292 | Creating sequences using range |
293 | 293 |
|
294 | 294 | ```py |
295 | | -lst = list(range(11)) |
| 295 | +lst = list(range(11)) |
296 | 296 | print(lst) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
297 | 297 | st = set(range(1, 11)) # 2 arguments indicate start and end of the sequence, step set to default 1 |
298 | 298 | print(st) # {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} |
@@ -431,26 +431,26 @@ for number in range(6): |
431 | 431 | 6. Iterate through the list, ['Python', 'Numpy','Pandas','Django', 'Flask'] using a for loop and print out the items. |
432 | 432 | 7. Use for loop to iterate from 0 to 100 and print only even numbers |
433 | 433 | 8. Use for loop to iterate from 0 to 100 and print only odd numbers |
434 | | - |
| 434 | + |
435 | 435 | ### Exercises: Level 2 |
436 | | - |
| 436 | + |
437 | 437 | 1. Use for loop to iterate from 0 to 100 and print the sum of all numbers. |
438 | 438 |
|
439 | | - ```sh |
440 | | - The sum of all numbers is 5050. |
441 | | - ``` |
| 439 | +```sh |
| 440 | +The sum of all numbers is 5050. |
| 441 | +``` |
442 | 442 |
|
443 | 443 | 1. Use for loop to iterate from 0 to 100 and print the sum of all evens and the sum of all odds. |
444 | 444 |
|
445 | | - ```sh |
446 | | - The sum of all evens is 2550. And the sum of all odds is 2500. |
447 | | - ``` |
| 445 | + ```sh |
| 446 | + The sum of all evens is 2550. And the sum of all odds is 2500. |
| 447 | + ``` |
448 | 448 |
|
449 | 449 | ### Exercises: Level 3 |
450 | 450 |
|
451 | 451 | 1. Go to the data folder and use the [countries.py](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/countries.py) file. Loop through the countries and extract all the countries containing the word _land_. |
452 | 452 | 1. This is a fruit list, ['banana', 'orange', 'mango', 'lemon'] reverse the order using loop. |
453 | | -2. Go to the data folder and use the [countries_data.py](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/countries-data.py) file. |
| 453 | +1. Go to the data folder and use the [countries_data.py](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/countries-data.py) file. |
454 | 454 | 1. What are the total number of languages in the data |
455 | 455 | 2. Find the ten most spoken languages from the data |
456 | 456 | 3. Find the 10 most populated countries in the world |
|
0 commit comments