Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 688ea6b

Browse files
committedDec 19, 2023
Add changes to Loops lesson
1 parent 2914d21 commit 688ea6b

File tree

9 files changed

+15
-2
lines changed

9 files changed

+15
-2
lines changed
 

‎Loops/Break keyword/task.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ always be `True`, such a loop becomes infinite. The most straightforward way to
55
an infinite loop is to use `while True`. The `break` keyword is used to
66
escape the loop.
77

8+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/6302#break).
89

910
Write a condition to exit the loop on its third iteration after evaluating if `animal`
1011
is equal to `elephant`. Use the `break` statement. The `zoo` list in the end should contain

‎Loops/Continue keyword/task.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ the current iteration only and proceed right to the next one. The loop returns t
55
`while` statement and evaluates the condition again. If there is no next item,
66
the `else` clause is executed if it is present.
77

8+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/6302#continue).
9+
810
Print only the odd numbers `1, 3, 5, 7, 9`.
911

1012
<div class='hint'>Use the <code>%</code> operator to check if <code>x</code> is even.</div>

‎Loops/Else with loops 2/task.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ The `else` statement will only be executed if `n` is a prime number, i.e. the `i
1818
`for` loop.
1919

2020
### Task
21-
22-
Inside the [function](course://Functions/Definition) `contains_even_number()`, write a `for` loop that would iterate over a list `lst` and, if an even element is found,
21+
Inside the [function](course://Loops/Else with loops 2) `contains_even_number()`, write a `for` loop that would iterate over a list `lst` and, if an even element is found,
2322
print `f"List {lst} contains an even number."` and exit the loop, if no such element is found, print `f"List {lst} does not contain an even number."`.
2423

2524
<div class="hint">

‎Loops/Else with loops/task.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Remember, an `else` after an `if` statement is skipped and NOT executed if the e
3434
`if` is `True`, while in the case of loops, an `else` clause is executed after the loop itself
3535
is completed (unless there was a `break` in there somewhere).
3636

37+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/6302).
38+
3739
In the code editor, add two lines of code to the second loop to make sure the loop only prints
3840
numbers 1 and 2 and never prints the phrase `"for loop is done"`.
3941

‎Loops/For loop/task.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ for each item. When the items are exhausted, the loop terminates.
88

99
You can read more about the `for` statement on <a href="https://docs.python.org/3/reference/compound_stmts.html#the-for-statement">this page</a> of Python Documentation.
1010

11+
For more structured and detailed information, you can also refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/6065).
12+
1113
Print each prime number from the `primes` list using the `for` loop. A prime
1214
number is a natural number greater than `1` that has no positive divisors
1315
other than `1` and itself.

‎Loops/List Comprehension/task.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Output:
2828
```
2929
List comprehensions are also more efficient computationally than a `for` loop.
3030

31+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/6315).
32+
3133
In the code editor, use list comprehension to build `my_efficient_list` from the elements of `my_inefficient_list`
3234
by adding $10$ to each of them. For example, the first element of `my_inefficient_list` is $1 + 10 = 11$,
3335
so the first element of `my_efficient_list` should be $11 + 10 = 21$, and so on.

‎Loops/Nested List Comprehension/task.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Output:
3333
[[0, 2, 4, 6, 8], [0, 2, 4, 6, 8], [0, 2, 4, 6, 8]]
3434
```
3535

36+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/6938#nested-list-comprehension).
37+
3638
### Task
3739

3840
Create a $10×10$ `matrix` such that each row (sublist) contains **characters** 0–9 from

‎Loops/Nested for Loop/task.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Note that any type of loop can be nested inside another loop.
2929
For example, a [`while` loop](course://Loops/While loop) (see further) can be nested inside a `for` loop, or vice versa.
3030
</details>
3131

32+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/6065#nested-loop).
3233

3334
You are given a tic-tac-toe board of 3x3, your task is to print every position. Coordinates along each side
3435
are stored in the list `coordinates`. The output should be:

‎Loops/While loop/task.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
A `while` loop is somewhat similar to an `if` statement: it executes some code if some
44
condition is `True`. The key difference is that it will continue to execute indented
55
code for as long as the condition is `True`. If the expression is `False`, the loop terminates.
6+
7+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/5940).
68

79
Print all squares from `1` to `9` `(1, 4, ... , 81)`. Use the `number` variable in a
810
`while` loop.

0 commit comments

Comments
 (0)
Please sign in to comment.