|
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. |
@@ -285,20 +285,15 @@ for number in numbers: |
285 | 285 | print('outside the loop') |
286 | 286 | ``` |
287 | 287 |
|
288 | | -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 | +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. |
289 | 289 |
|
290 | 290 | ### The Range Function |
291 | 291 |
|
292 | | -The _range()_ function is used to loop through a set of code a certain number of times. The _range(start,end, step)_ takes three parameters: starting, ending and increment. |
293 | | - start: integer starting from which the sequence of integers is to be returned |
294 | | - stop: integer before which the sequence of integers is to be returned. |
295 | | - The range of integers end at stop – 1. |
296 | | - step: integer value which determines the increment between each integer in the sequence |
297 | | -By default it starts from 0 and the increment is 1. The range sequence needs at least 1 argument (end). |
| 292 | +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). |
298 | 293 | Creating sequences using range |
299 | 294 |
|
300 | 295 | ```py |
301 | | -lst = list(range(11)) |
| 296 | +lst = list(range(11)) |
302 | 297 | print(lst) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
303 | 298 | st = set(range(1, 11)) # 2 arguments indicate start and end of the sequence, step set to default 1 |
304 | 299 | print(st) # {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} |
@@ -441,26 +436,26 @@ for number in range(6): |
441 | 436 | 6. Iterate through the list, ['Python', 'Numpy','Pandas','Django', 'Flask'] using a for loop and print out the items. |
442 | 437 | 7. Use for loop to iterate from 0 to 100 and print only even numbers |
443 | 438 | 8. Use for loop to iterate from 0 to 100 and print only odd numbers |
444 | | - |
| 439 | + |
445 | 440 | ### Exercises: Level 2 |
446 | | - |
| 441 | + |
447 | 442 | 1. Use for loop to iterate from 0 to 100 and print the sum of all numbers. |
448 | 443 |
|
449 | | - ```sh |
450 | | - The sum of all numbers is 5050. |
451 | | - ``` |
| 444 | +```sh |
| 445 | +The sum of all numbers is 5050. |
| 446 | +``` |
452 | 447 |
|
453 | 448 | 2. Use for loop to iterate from 0 to 100 and print the sum of all evens and the sum of all odds. |
454 | 449 |
|
455 | | - ```sh |
456 | | - The sum of all evens is 2550. And the sum of all odds is 2500. |
457 | | - ``` |
| 450 | + ```sh |
| 451 | + The sum of all evens is 2550. And the sum of all odds is 2500. |
| 452 | + ``` |
458 | 453 |
|
459 | 454 | ### Exercises: Level 3 |
460 | 455 |
|
461 | 456 | 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_. |
462 | | -2. This is a fruit list, ['banana', 'orange', 'mango', 'lemon'] reverse the order using loop. |
463 | | -3. 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. |
| 457 | +1. This is a fruit list, ['banana', 'orange', 'mango', 'lemon'] reverse the order using loop. |
| 458 | +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. |
464 | 459 | 1. What are the total number of languages in the data |
465 | 460 | 2. Find the ten most spoken languages from the data |
466 | 461 | 3. Find the 10 most populated countries in the world |
|
0 commit comments