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 b2dde8f

Browse files
committedDec 18, 2023
Add changes to Variables lesson
1 parent 2914d21 commit b2dde8f

File tree

12 files changed

+102
-82
lines changed

12 files changed

+102
-82
lines changed
 

‎Variables/Arithmetic operators/arithmetic_operators.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
number = 9.0 # Float number
1+
init_number = 9.0 # Float number
22

3-
division_result = number / 2
3+
division_result = init_number / 2
44

5-
division_remainder = number % 2
5+
division_remainder = init_number % 2
66

77
multiplication_result = division_result * 2
88

99
addition_result = multiplication_result + division_remainder
1010

11-
subtraction_result = number - multiplication_result
11+
subtraction_result = init_number - multiplication_result
1212

13-
floor_result = number // 2
13+
floor_result = init_number // 2
1414

1515
power_result = multiplication_result ** 3
1616

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
type: edu
22
files:
3-
- name: arithmetic_operators.py
4-
visible: true
5-
placeholders:
6-
- offset: 54
7-
length: 10
8-
placeholder_text: '# divide the number by two'
9-
- offset: 87
10-
length: 10
11-
placeholder_text: '# get the remainder of the division of the number by two'
12-
- offset: 123
13-
length: 19
14-
placeholder_text: '# multiply the division result by 2'
15-
- offset: 162
16-
length: 42
17-
placeholder_text: '# add the division remainder to the multiplication result'
18-
- offset: 227
19-
length: 30
20-
placeholder_text: '# subtract the multiplication result from the initial number'
21-
- offset: 274
22-
length: 11
23-
placeholder_text: '# perform a floor division of number by 2'
24-
- offset: 302
25-
length: 26
26-
placeholder_text: '# raise the multiplication result to the power of 3'
27-
- name: tests/test_task.py
28-
visible: false
29-
feedback_link: https://docs.google.com/forms/d/e/1FAIpQLSfRlDlldKfuq-cHMNFfHMER61P1PRIan7KG6yp1GvaweDI7GA/viewform?usp=pp_url&entry.2103429047=Variables+/+Arithmetic+Operators
3+
- name: arithmetic_operators.py
4+
visible: true
5+
placeholders:
6+
- offset: 59
7+
length: 15
8+
placeholder_text: '# divide the init_number by 2'
9+
- offset: 97
10+
length: 15
11+
placeholder_text: '# get the remainder of the division of the init_number by 2'
12+
- offset: 138
13+
length: 19
14+
placeholder_text: '# multiply the division_result by 2'
15+
- offset: 177
16+
length: 42
17+
placeholder_text: '# add the division_remainder to the multiplication_result'
18+
- offset: 242
19+
length: 35
20+
placeholder_text: '# subtract the multiplication_result from the init_number'
21+
- offset: 294
22+
length: 16
23+
placeholder_text: '# perform a floor division of init_number by 2'
24+
- offset: 327
25+
length: 26
26+
placeholder_text: '# raise the multiplication_result to the power of 3'
27+
- name: tests/test_task.py
28+
visible: false
29+
feedback_link: https://docs.google.com/forms/d/e/1FAIpQLSfRlDlldKfuq-cHMNFfHMER61P1PRIan7KG6yp1GvaweDI7GA/viewform?usp=pp_url&entry.2103429047=Variables+/+Arithmetic+Operators

‎Variables/Arithmetic operators/task.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,29 @@ either both be numbers, or one argument must be an integer and the other – a s
1717

1818
- The `-` (subtraction) operator yields the difference of its arguments.
1919

20+
For example
21+
```python
22+
a = 16
23+
b = 3
24+
result = a // b # result will be 5
25+
result = a % b # result will be 1
26+
result = a ** 2 # result will be 256 (16 in power of 2)
27+
```
28+
2029
The binary arithmetic operations have the conventional priority levels. Note that
2130
some of these operations also apply to certain non-numeric types.
2231

2332
You can read more on this topic <a href="https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations">here</a>.
33+
34+
For more structured and detailed information, you can also refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/5865).
35+
2436
### Task
25-
- Divide the value stored in `number` by `2`.
37+
- Divide the value stored in `init_number` by `2`.
2638
- Calculate a remainder of such a division.
27-
- Multiply the division result by `2`.
28-
- Add the division remainder to the multiplication result.
29-
- Subtract the multiplication result from the number.
30-
- Perform a floor division of `number` by 2.
39+
- Multiply the `division_result` by `2`.
40+
- Add the `division_remainder` to the `multiplication_result`.
41+
- Subtract the `multiplication_result` from the `init_number`.
42+
- Perform a floor division of `init_number` by 2.
3143
- Raise the `multiplication_result` to the power of 3
3244

3345
<div class='hint'>First, use the <code>/</code> operator.</div>
@@ -38,3 +50,7 @@ You can read more on this topic <a href="https://docs.python.org/3/reference/exp
3850
<div class='hint'>Then use the <code>+</code> operator.</div>
3951

4052
<div class='hint'>Then use the <code>-</code> operator.</div>
53+
54+
<div class='hint'>Then use the <code>//</code> operator.</div>
55+
56+
<div class='hint'>Then use the <code>**</code> operator.</div>

‎Variables/Boolean operators/task.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
Boolean is a type of value that can only be `True` or `False`. The `==` (equality) operator
44
compares two variables and checks whether they are equal. You will learn more about boolean operators in a later [task](course://Condition expressions/Boolean operators).
55

6+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/6025).
7+
68
### Task
79
- Check whether the variable `two` is equal to `three`.
810
- Check if the variable `is_equal` has a deceiving name.

‎Variables/Comparison operators/task.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ that of any arithmetic, shifting or bitwise operation. Comparisons yield boolean
2222
values: either `True` or `False`. Comparisons can be chained arbitrarily, and
2323
expressions like `a < b < c` have the
2424
conventional mathematical meaning. Read more on comparisons <a href="https://docs.python.org/3/reference/expressions.html#comparisons">here</a>.
25+
26+
For more structured and detailed information, you can also refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/5920).
27+
2528
### Task
2629
- Check whether the value of the variable `three` is strictly greater than the value of
2730
the variable `two`.

‎Variables/Type conversion/task.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
There are several built-in functions that let you convert one data type into another.
44
These functions return a new object representing the converted value. `int(x)`
55
converts `x` into an integer. `float(x)` converts `x` into a floating-point number. `str(x)`
6-
converts object `x` into a string representation.
6+
converts object `x` into a string representation.
7+
8+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/6224).
9+
710
### Task
811
Convert `float_number` into an integer.
912

‎Variables/Undefined variable/task.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ Variable names may only contain Latin letters, digits, and/or the underscore
44
character, and they cannot start with a digit. They also cannot be any of the
55
reserved <a href="https://docs.python.org/3/reference/lexical_analysis.html#keywords">keywords</a>.
66
### Task
7-
Check what happens if you use a variable which is not defined yet. Change and run the code in the editor – try to print out an undefined name.
7+
Check what happens if you use a variable which is not defined yet. Change and run the code in the editor – try to print out an **undefined** name (i.e. type the name of an undefined variable inside the brackets of the `print` statement).
88
This should cause an exception - a `NameError`.
99

1010
Note, that "check" command only runs the testing system, and you will not see the output, so you need to run the file.
1111

12-
<div class="hint">Type the name of an undefined variable inside the brackets of the <code>print</code> statement.
13-
Note that variable names must start with a letter and can contain only letters, '_', and numbers.</div>
12+
<div class="hint">for example, try to print <code>var1</code> variable instead of <code>variable</code></div>
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
type: edu
22
files:
3-
- name: variable_definition.py
4-
visible: true
5-
placeholders:
6-
- offset: 231
7-
length: 1
8-
placeholder_text: ???
9-
- offset: 337
10-
length: 1
11-
placeholder_text: '# Assign a new value'
12-
- offset: 472
13-
length: 5
14-
placeholder_text: '# Assign 2 to both a and b here'
15-
- name: tests/test_task.py
16-
visible: false
3+
- name: variable_definition.py
4+
visible: true
5+
placeholders:
6+
- offset: 227
7+
length: 1
8+
placeholder_text: ???
9+
- offset: 320
10+
length: 10
11+
placeholder_text: '# Assign a new value'
12+
- offset: 445
13+
length: 5
14+
placeholder_text: '# Assign 2 to both a and b here'
15+
- name: tests/test_task.py
16+
visible: false
1717
feedback_link: https://docs.google.com/forms/d/e/1FAIpQLSfRlDlldKfuq-cHMNFfHMER61P1PRIan7KG6yp1GvaweDI7GA/viewform?usp=pp_url&entry.2103429047=Variables+/+Variable+Definition

‎Variables/Variable definition/task.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
Variables are used to store values so we can refer to them later. A variable
44
is like a label, and in Python we use the ' `=` ' symbol, known as the
55
assignment operator, to assign a value to a variable. An assignment can be
6-
chained, e.g., `a = b = 2`.
6+
chained, e.g., `a = b = 2`.
7+
8+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/5859).
9+
710
### Task
8-
- Change the value stored in the variable `greetings`.
9-
- Use the chain assignment to store 2 in both `a` and `b` on line 15.
11+
1. Assign `World` string to `name` variable
12+
2. On line 10 change the value in the `name` variable with your actual name.
13+
3. Use the chain assignment to store 2 in both `a` and `b` on line 15.
1014

11-
<div class="hint">Type a new value in the answer placeholder.</div>
15+
<div class="hint">Type a new "name" variable value in the answer placeholder.</div>

‎Variables/Variable definition/tests/test_task.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,7 @@ def setUp(self):
2727
"errors and warnings.".format(str(e)))
2828

2929
def test_assignment_operator(self):
30-
expected_first_greetings = "greetings = greetings"
31-
actual_output = self.actualOutput.getvalue()
32-
33-
self.assertIn(expected_first_greetings, actual_output, msg="The line expressing greetings after the initial "
34-
"assignment was not found. Check that the variable is "
35-
"assigned properly and that the print statement "
36-
"is intact.")
37-
38-
def test_assignment_operator2(self):
39-
expected_first_greetings = "greetings = greetings"
30+
expected_first_greetings = "Hello, World"
4031
actual_output = self.actualOutput.getvalue()
4132

4233
self.assertIn(expected_first_greetings, actual_output, msg="The line expressing greetings after the initial "
@@ -45,16 +36,16 @@ def test_assignment_operator2(self):
4536
"is intact.")
4637

4738
def test_variable(self):
48-
unexpected_greetings = "greetings"
39+
unexpected_name = "World"
4940

5041
try:
51-
actual_greetings = try_import().greetings
42+
actual_name = try_import().name
5243
except AttributeError:
53-
self.fail(msg="The variable greetings seems to be undefined. Do not remove it from the task code.")
44+
self.fail(msg="The variable name seems to be undefined. Do not remove it from the task code.")
5445

55-
self.assertNotEqual(unexpected_greetings, actual_greetings, msg="The variable greetings doesn't seem to be "
56-
"reassigned. You should change it to something "
57-
"else.")
46+
self.assertNotEqual(unexpected_name, actual_name, msg="The variable name doesn't seem to be "
47+
"reassigned. You should change it to something "
48+
"else.")
5849

5950
def test_chained_assignment(self):
6051
expected_a = expected_b = 2

‎Variables/Variable definition/variable_definition.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
# For now: it is used to convert the variable "a" into a string.
44
print("a = " + str(a))
55

6-
# Assign "greetings" to the variable using the assignment operator
7-
greetings = "greetings"
8-
print("greetings = " + str(greetings))
9-
# Reassign anything to the variable here
10-
greetings = 5
11-
print("greetings = " + str(greetings))
6+
# Assign "World" to the name variable using the assignment operator
7+
name = "World"
8+
print("Hello, " + str(name))
9+
# Reassign name variable with your actual name
10+
name = "Username"
11+
print("Hello, " + str(name))
1212

1313

14-
# This is called a "chained assignment". It assigns the value 2 to variables "a" and "b".
14+
# Use here the chain assignment to assigns the value 2 to variables "a" and "b".
1515
a = b = 2
1616
print("a = " + str(a))
1717
print("b = " + str(b))

‎Variables/Variable types/task.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ and an `int` is a number without a decimal point.
2121
For more information on this topic, refer to the "<a href="https://docs.python.org/3/reference/datamodel.html#objects-values-and-types">Objects, values and types</a>"
2222
and "<a href="https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy">The standard type hierarchy</a>" sections in Python Documentation.
2323

24+
For more structured and detailed information, you can also refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/5852).
25+
2426
### Task
2527
Print the type of the variable `float_number`.
2628

0 commit comments

Comments
 (0)
Please sign in to comment.