From 850c6dff6f12acbf0d027e9ef8e43d8b2687f684 Mon Sep 17 00:00:00 2001 From: bonnieblack14 Date: Tue, 28 Oct 2025 16:36:53 +0300 Subject: [PATCH 1/3] =?UTF-8?q?rename=20Complex=20=E2=86=92=20ComplexNumbe?= =?UTF-8?q?r=20and=20create()=20=E2=86=92=20set=5Fparts()=20for=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes and objects/The self parameter/self_parameter.py | 8 ++++---- Classes and objects/The self parameter/task-info.yaml | 4 ++-- Classes and objects/__str__ vs __repr__/str_and_repr.py | 6 +++--- Classes and objects/__str__ vs __repr__/task-info.yaml | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Classes and objects/The self parameter/self_parameter.py b/Classes and objects/The self parameter/self_parameter.py index 2e5d59e5..2ccfbf6f 100644 --- a/Classes and objects/The self parameter/self_parameter.py +++ b/Classes and objects/The self parameter/self_parameter.py @@ -1,5 +1,5 @@ -class Complex: - def create(self, real_part, imag_part): +class ComplexNumber: + def set_parts(self, real_part, imag_part): self.r = real_part self.i = imag_part @@ -7,8 +7,8 @@ def build(self): self.num = complex(self.r, self.i) -complex_number = Complex() # Instantiate a complex number object -complex_number.create(12, 5) # Call create method with real_part = 12 and imag_part = 5 +complex_number = ComplexNumber() # Instantiate a complex number object +complex_number.set_parts(12, 5) # Call set_parts method with real_part = 12 and imag_part = 5 complex_number.build() # Build the complex number print(complex_number.num) diff --git a/Classes and objects/The self parameter/task-info.yaml b/Classes and objects/The self parameter/task-info.yaml index f9ce0168..23dc5166 100644 --- a/Classes and objects/The self parameter/task-info.yaml +++ b/Classes and objects/The self parameter/task-info.yaml @@ -3,10 +3,10 @@ files: - name: self_parameter.py visible: true placeholders: - - offset: 484 + - offset: 505 length: 22 placeholder_text: "# Update the current attribute by adding the amount to it." - - offset: 550 + - offset: 571 length: 12 placeholder_text: ??? - name: tests/__init__.py diff --git a/Classes and objects/__str__ vs __repr__/str_and_repr.py b/Classes and objects/__str__ vs __repr__/str_and_repr.py index c0a2ecc4..1d65dd2e 100644 --- a/Classes and objects/__str__ vs __repr__/str_and_repr.py +++ b/Classes and objects/__str__ vs __repr__/str_and_repr.py @@ -1,16 +1,16 @@ -class Complex: +class ComplexNumber: def __init__(self, real_part, imag_part): self.real = real_part self.img = imag_part def __repr__(self): - return f'Complex({self.real}, {self.img})' + return f'ComplexNumber({self.real}, {self.img})' def __str__(self): return f'{self.real} + i{self.img}' -x = Complex(2, 5) +x = ComplexNumber(2, 5) print(str(x)) print(repr(x)) diff --git a/Classes and objects/__str__ vs __repr__/task-info.yaml b/Classes and objects/__str__ vs __repr__/task-info.yaml index 19b7d98c..a84975e7 100644 --- a/Classes and objects/__str__ vs __repr__/task-info.yaml +++ b/Classes and objects/__str__ vs __repr__/task-info.yaml @@ -3,10 +3,10 @@ files: - name: str_and_repr.py visible: true placeholders: - - offset: 455 + - offset: 473 length: 46 placeholder_text: ??? - - offset: 541 + - offset: 559 length: 45 placeholder_text: ??? - name: tests/__init__.py From a5e42559a9a63aa5852dc6947eb45c83f9175566 Mon Sep 17 00:00:00 2001 From: bonnieblack14 Date: Tue, 28 Oct 2025 17:23:21 +0300 Subject: [PATCH 2/3] =?UTF-8?q?rename=20first=20Complex=20=E2=86=92=20Comp?= =?UTF-8?q?lexBuilder=20and=20change=20task.md=20for=20the=20second=20Comp?= =?UTF-8?q?lex=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes and objects/The self parameter/self_parameter.py | 4 ++-- Classes and objects/The self parameter/task-info.yaml | 4 ++-- Classes and objects/__str__ vs __repr__/task.md | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Classes and objects/The self parameter/self_parameter.py b/Classes and objects/The self parameter/self_parameter.py index 2ccfbf6f..b87f4611 100644 --- a/Classes and objects/The self parameter/self_parameter.py +++ b/Classes and objects/The self parameter/self_parameter.py @@ -1,4 +1,4 @@ -class ComplexNumber: +class ComplexBuilder: def set_parts(self, real_part, imag_part): self.r = real_part self.i = imag_part @@ -7,7 +7,7 @@ def build(self): self.num = complex(self.r, self.i) -complex_number = ComplexNumber() # Instantiate a complex number object +complex_number = ComplexBuilder() # Instantiate a complex number object complex_number.set_parts(12, 5) # Call set_parts method with real_part = 12 and imag_part = 5 complex_number.build() # Build the complex number print(complex_number.num) diff --git a/Classes and objects/The self parameter/task-info.yaml b/Classes and objects/The self parameter/task-info.yaml index 23dc5166..e6b9402b 100644 --- a/Classes and objects/The self parameter/task-info.yaml +++ b/Classes and objects/The self parameter/task-info.yaml @@ -3,10 +3,10 @@ files: - name: self_parameter.py visible: true placeholders: - - offset: 505 + - offset: 507 length: 22 placeholder_text: "# Update the current attribute by adding the amount to it." - - offset: 571 + - offset: 573 length: 12 placeholder_text: ??? - name: tests/__init__.py diff --git a/Classes and objects/__str__ vs __repr__/task.md b/Classes and objects/__str__ vs __repr__/task.md index 5eb5b0e1..0fcf03ec 100644 --- a/Classes and objects/__str__ vs __repr__/task.md +++ b/Classes and objects/__str__ vs __repr__/task.md @@ -24,7 +24,7 @@ defined in the object's class. Our own defined class should therefore have a `__repr__` if we need detailed information for debugging. Also, if we think it would be useful to have a string representation for users, we should create -a `__str__` function. Check out another implementation of the class `Complex` in the code editor. Run the code +a `__str__` function. Check out another approach to representing complex numbers using the `ComplexNumber` class in the code editor. Run the code to see what each of the two `print` statements prints. For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/7139#str__-vs-__repr?utm_source=jba&utm_medium=jba_courses_links). From 0403d362b3f5251ea3b5b21701ae63222c3b67fe Mon Sep 17 00:00:00 2001 From: bonnieblack14 Date: Tue, 28 Oct 2025 17:36:55 +0300 Subject: [PATCH 3/3] =?UTF-8?q?rename=20another=20Complex=20class=20?= =?UTF-8?q?=E2=86=92=20ComplexNumber?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes and objects/Special __init__ method/task.md | 4 ++-- Classes and objects/__str__ vs __repr__/task.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Classes and objects/Special __init__ method/task.md b/Classes and objects/Special __init__ method/task.md index 0aedd742..3790a61f 100644 --- a/Classes and objects/Special __init__ method/task.md +++ b/Classes and objects/Special __init__ method/task.md @@ -23,13 +23,13 @@ The `__init__()` method may receive arguments for greater flexibility. In that case, arguments given to the class instantiation operator are passed on to `__init__()`. For example: ```python -class Complex: +class ComplexNumber: def __init__(self, real_part, imag_part): self.r = real_part self.i = imag_part self.num = complex(self.r, self.i) -x = Complex(3.0, -4.5) # Instantiating a complex number +x = ComplexNumber(3.0, -4.5) # Instantiating a complex number x.num ``` ```text diff --git a/Classes and objects/__str__ vs __repr__/task.md b/Classes and objects/__str__ vs __repr__/task.md index 0fcf03ec..704f724a 100644 --- a/Classes and objects/__str__ vs __repr__/task.md +++ b/Classes and objects/__str__ vs __repr__/task.md @@ -24,7 +24,7 @@ defined in the object's class. Our own defined class should therefore have a `__repr__` if we need detailed information for debugging. Also, if we think it would be useful to have a string representation for users, we should create -a `__str__` function. Check out another approach to representing complex numbers using the `ComplexNumber` class in the code editor. Run the code +a `__str__` function. Check out another implementation of the class `ComplexNumber` in the code editor. Run the code to see what each of the two `print` statements prints. For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/7139#str__-vs-__repr?utm_source=jba&utm_medium=jba_courses_links).