From ac36e0317d21b415723af2ac087420d43c76e215 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 3 Jan 2024 03:14:23 +0000 Subject: [PATCH 1/9] =?UTF-8?q?A=C3=B1adir=20ejercicio=20043-inheritance?= =?UTF-8?q?=5Fand=5Fpolymorphism?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../README.es.md | 47 +++++++++++++++++++ .../README.md | 46 ++++++++++++++++++ .../043-inheritance_and_polymorphism/app.py | 18 +++++++ .../solution.hide.py | 34 ++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 exercises/043-inheritance_and_polymorphism/README.es.md create mode 100644 exercises/043-inheritance_and_polymorphism/README.md create mode 100644 exercises/043-inheritance_and_polymorphism/app.py create mode 100644 exercises/043-inheritance_and_polymorphism/solution.hide.py diff --git a/exercises/043-inheritance_and_polymorphism/README.es.md b/exercises/043-inheritance_and_polymorphism/README.es.md new file mode 100644 index 00000000..f6064a79 --- /dev/null +++ b/exercises/043-inheritance_and_polymorphism/README.es.md @@ -0,0 +1,47 @@ +# `043` inheritance and polymorphism + +Ahora que entendemos qué es una clase y algunas de sus características, hablemos sobre dos nuevos conceptos relacionados con las clases: herencia y polimorfismo. Considera el siguiente ejemplo: + +```py +class HighSchoolStudent(Student): # Agrega la clase padre dentro de los paréntesis + def __init__(self, name, age, grade, specialization): + super().__init__(name, age, grade) + self.specialization = specialization + + def study(self, hours): + print(f"{self.name} is a high school student specializing in {self.specialization} and is studying for {hours} hours for exams.") + +# Creando una instancia de HighSchoolStudent +high_school_student = HighSchoolStudent("John", 16, 85, "Science") +high_school_student.introduce() # Podemos llamar a este método gracias a la herencia +high_school_student.study(4) # Este método ha sido ligeramente modificado y ahora imprime un string diferente +``` + +Suponiendo que la clase `Student` del ejercicio anterior está definida justo encima de esta clase `HighSchoolStudent`, para heredar sus métodos y atributos, simplemente incluimos el nombre de la clase que queremos heredar (la clase padre) dentro de los paréntesis de la clase hija (`HighSchoolStudent`). Como puedes ver, ahora podemos usar el método `introduce` de la clase `Student` sin tener que codificarlo nuevamente, haciendo nuestro código más eficiente. Lo mismo se aplica a los atributos; no necesitamos redefinirlos. + +Además, tenemos la flexibilidad de agregar nuevos métodos exclusivamente para esta clase o incluso sobreescribir un método heredado si es necesario, como se demuestra en el método `study` que está ligeramente modificado con respecto a la clase `Student`; esto se llama polimorfismo. + +## 📝 Instrucciones: + +1. Crea una clase llamada `CollegeStudent` que herede de la clase `Student` ya definida. + +2. Agrega un nuevo atributo llamado `major` para representar la carrera que están estudiando. + +3. Modifica el método heredado `introduce` para imprimir este string: + +```py +"Hi there! I'm , a college student majoring in ." +``` + +4. Agrega un nuevo método llamado `attend_lecture` que imprima el siguiente string: + +```py +" is attending a lecture for students." +``` + +5. Crea una instancia de tu nueva clase y llama a cada uno de sus métodos. Ejecuta tu código para asegurarte de que funcione. + + +## 💡 Pista: + ++ Puede que hayas notado el uso de un nuevo método `super()`, que es necesario para heredar de una clase padre. Observa dónde se encuentra ubicado y lee más sobre él aquí: [Entendiendo super() en Python](https://realpython.com/python-super/). \ No newline at end of file diff --git a/exercises/043-inheritance_and_polymorphism/README.md b/exercises/043-inheritance_and_polymorphism/README.md new file mode 100644 index 00000000..9ff0755c --- /dev/null +++ b/exercises/043-inheritance_and_polymorphism/README.md @@ -0,0 +1,46 @@ +# `043` inheritance and polymorphism + +Now that we understand what a class is and some of its characteristics, let's talk about two new concepts related to classes: inheritance and polymorphism. Consider the following example: + +```py +class HighSchoolStudent(Student): # Add the parent class inside the parenthesis + def __init__(self, name, age, grade, specialization): + super().__init__(name, age, grade) + self.specialization = specialization + + def study(self, hours): + print(f"{self.name} is a high school student specializing in {self.specialization} and is studying for {hours} hours for exams.") + +# Creating an instance of HighSchoolStudent +high_school_student = HighSchoolStudent("John", 16, 85, "Science") +high_school_student.introduce() # We can call this method thanks to inheritance +high_school_student.study(4) # This method has been slightly modified and now it prints a different string +``` + +Assuming that the `Student` class from the previous exercise is coded just above this `HighSchoolStudent` class, to inherit its methods and attributes, we simply include the name of the class we want to inherit from (the parent class) inside the parentheses of the child class (`HighSchoolStudent`). As you can see, we can now use the `introduce` method from the `Student` class without having to code it again, making our code more efficient. The same applies to attributes; we don't need to redefine them. + +Additionally, we have the flexibility to add new methods exclusively for this class or even override an inherited method if needed, as demonstrated in the `study` method which is slightly modified from the `Student` method; this is called **polymorphism**. + +## 📝 Instructions: + +1. Create a class called `CollegeStudent` which inherits from the already defined `Student` class. + +2. Add a new attribute called `major` to represent the major they are studying. + +3. Modify the inherited `introduce` method to print this string: + +```py +"Hi there! I'm , a college student majoring in ." +``` + +4. Add a new method called `attend_lecture` that prints the following string: + +```py +" is attending a lecture for students." +``` + +5. Create an instance of your newly created class and call each of its methods. Execute your code to ensure it works. + +## 💡 Hint: + ++ You may have noticed the use of a new method `super()` which is necessary for inheriting from a parent class. Take a look at where it is positioned and have a read about it: [Understanding Python's super()](https://realpython.com/python-super/). \ No newline at end of file diff --git a/exercises/043-inheritance_and_polymorphism/app.py b/exercises/043-inheritance_and_polymorphism/app.py new file mode 100644 index 00000000..2bff00cf --- /dev/null +++ b/exercises/043-inheritance_and_polymorphism/app.py @@ -0,0 +1,18 @@ +### DON'T modify this code ### + +class Student: + def __init__(self, name, age, grade): + self.name = name + self.age = age + self.grade = grade + + def introduce(self): + print(f"Hello! I am {self.name}, I am {self.age} years old, and my current grade is {self.grade}.") + + def study(self, hours): + print(f"{self.name} is studying for {hours} hours.") + +### DON'T modify the code above ### + +### ↓ Your code here ↓ ### + diff --git a/exercises/043-inheritance_and_polymorphism/solution.hide.py b/exercises/043-inheritance_and_polymorphism/solution.hide.py new file mode 100644 index 00000000..0badd70c --- /dev/null +++ b/exercises/043-inheritance_and_polymorphism/solution.hide.py @@ -0,0 +1,34 @@ +### DON'T modify this code ### + +class Student: + def __init__(self, name, age, grade): + self.name = name + self.age = age + self.grade = grade + + def introduce(self): + print(f"Hello! I am {self.name}, I am {self.age} years old, and my current grade is {self.grade}.") + + def study(self, hours): + print(f"{self.name} is studying for {hours} hours.") + +### DON'T modify the code above ### + +### ↓ Your code here ↓ ### + +class CollegeStudent(Student): + def __init__(self, name, age, grade, major): + super().__init__(name, age, grade) + self.major = major + + def introduce(self): + print(f"Hi there! I'm {self.name}, a college student majoring in {self.major}.") + + def attend_lecture(self): + print(f"{self.name} is attending a lecture for {self.major} students.") + + +college_student = CollegeStudent("Alice", 20, 90, "Computer Science") +college_student.introduce() +college_student.study(3) +college_student.attend_lecture() \ No newline at end of file From 74207fb966c23edf5771d1d07b5cfa0f0ad56af8 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 3 Jan 2024 04:18:50 +0100 Subject: [PATCH 2/9] Update README.es.md --- exercises/043-inheritance_and_polymorphism/README.es.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/043-inheritance_and_polymorphism/README.es.md b/exercises/043-inheritance_and_polymorphism/README.es.md index f6064a79..0f85cc24 100644 --- a/exercises/043-inheritance_and_polymorphism/README.es.md +++ b/exercises/043-inheritance_and_polymorphism/README.es.md @@ -19,7 +19,7 @@ high_school_student.study(4) # Este método ha sido ligeramente modificado y ah Suponiendo que la clase `Student` del ejercicio anterior está definida justo encima de esta clase `HighSchoolStudent`, para heredar sus métodos y atributos, simplemente incluimos el nombre de la clase que queremos heredar (la clase padre) dentro de los paréntesis de la clase hija (`HighSchoolStudent`). Como puedes ver, ahora podemos usar el método `introduce` de la clase `Student` sin tener que codificarlo nuevamente, haciendo nuestro código más eficiente. Lo mismo se aplica a los atributos; no necesitamos redefinirlos. -Además, tenemos la flexibilidad de agregar nuevos métodos exclusivamente para esta clase o incluso sobreescribir un método heredado si es necesario, como se demuestra en el método `study` que está ligeramente modificado con respecto a la clase `Student`; esto se llama polimorfismo. +Además, tenemos la flexibilidad de agregar nuevos métodos exclusivamente para esta clase o incluso sobreescribir un método heredado si es necesario, como se demuestra en el método `study` que está ligeramente modificado con respecto a la clase `Student`; esto se llama **polimorfismo**. ## 📝 Instrucciones: @@ -44,4 +44,4 @@ Además, tenemos la flexibilidad de agregar nuevos métodos exclusivamente para ## 💡 Pista: -+ Puede que hayas notado el uso de un nuevo método `super()`, que es necesario para heredar de una clase padre. Observa dónde se encuentra ubicado y lee más sobre él aquí: [Entendiendo super() en Python](https://realpython.com/python-super/). \ No newline at end of file ++ Puede que hayas notado el uso de un nuevo método `super()`, que es necesario para heredar de una clase padre. Observa dónde se encuentra ubicado y lee más sobre él aquí: [Entendiendo super() en Python](https://realpython.com/python-super/). From 5344d1580428256bc2e855a568b7aa2fde8686cc Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 3 Jan 2024 04:22:58 +0100 Subject: [PATCH 3/9] Update README.md --- exercises/043-inheritance_and_polymorphism/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/043-inheritance_and_polymorphism/README.md b/exercises/043-inheritance_and_polymorphism/README.md index 9ff0755c..15d313db 100644 --- a/exercises/043-inheritance_and_polymorphism/README.md +++ b/exercises/043-inheritance_and_polymorphism/README.md @@ -19,7 +19,7 @@ high_school_student.study(4) # This method has been slightly modified and now i Assuming that the `Student` class from the previous exercise is coded just above this `HighSchoolStudent` class, to inherit its methods and attributes, we simply include the name of the class we want to inherit from (the parent class) inside the parentheses of the child class (`HighSchoolStudent`). As you can see, we can now use the `introduce` method from the `Student` class without having to code it again, making our code more efficient. The same applies to attributes; we don't need to redefine them. -Additionally, we have the flexibility to add new methods exclusively for this class or even override an inherited method if needed, as demonstrated in the `study` method which is slightly modified from the `Student` method; this is called **polymorphism**. +Additionally, we have the flexibility to add new methods exclusively for this class or even override an inherited method if needed, as demonstrated in the `study` method, which is slightly modified from the `Student` method; this is called **polymorphism**. ## 📝 Instructions: @@ -43,4 +43,4 @@ Additionally, we have the flexibility to add new methods exclusively for this cl ## 💡 Hint: -+ You may have noticed the use of a new method `super()` which is necessary for inheriting from a parent class. Take a look at where it is positioned and have a read about it: [Understanding Python's super()](https://realpython.com/python-super/). \ No newline at end of file ++ You may have noticed the use of a new method `super()` which is necessary for inheriting from a parent class. Take a look at where it is positioned and have a read about it: [Understanding Python's super()](https://realpython.com/python-super/). From 2a5eab1c65acb0536b25ec26d9a5dd11a6ce08a4 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 24 Jan 2024 00:56:45 +0100 Subject: [PATCH 4/9] Update README.es.md --- exercises/043-inheritance_and_polymorphism/README.es.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/043-inheritance_and_polymorphism/README.es.md b/exercises/043-inheritance_and_polymorphism/README.es.md index 0f85cc24..86e8efc0 100644 --- a/exercises/043-inheritance_and_polymorphism/README.es.md +++ b/exercises/043-inheritance_and_polymorphism/README.es.md @@ -9,7 +9,7 @@ class HighSchoolStudent(Student): # Agrega la clase padre dentro de los parént self.specialization = specialization def study(self, hours): - print(f"{self.name} is a high school student specializing in {self.specialization} and is studying for {hours} hours for exams.") + return f"{self.name} is a high school student specializing in {self.specialization} and is studying for {hours} hours for exams." # Creando una instancia de HighSchoolStudent high_school_student = HighSchoolStudent("John", 16, 85, "Science") @@ -27,13 +27,13 @@ Además, tenemos la flexibilidad de agregar nuevos métodos exclusivamente para 2. Agrega un nuevo atributo llamado `major` para representar la carrera que están estudiando. -3. Modifica el método heredado `introduce` para imprimir este string: +3. Modifica el método heredado `introduce` para retornar este string: ```py "Hi there! I'm , a college student majoring in ." ``` -4. Agrega un nuevo método llamado `attend_lecture` que imprima el siguiente string: +4. Agrega un nuevo método llamado `attend_lecture` que retorne el siguiente string: ```py " is attending a lecture for students." From a776bdbacfe0db38f0b1771045b5f4ce602a5dc8 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 24 Jan 2024 01:11:17 +0100 Subject: [PATCH 5/9] Update solution.hide.py --- .../solution.hide.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/exercises/043-inheritance_and_polymorphism/solution.hide.py b/exercises/043-inheritance_and_polymorphism/solution.hide.py index 0badd70c..c6b3ffde 100644 --- a/exercises/043-inheritance_and_polymorphism/solution.hide.py +++ b/exercises/043-inheritance_and_polymorphism/solution.hide.py @@ -7,10 +7,10 @@ def __init__(self, name, age, grade): self.grade = grade def introduce(self): - print(f"Hello! I am {self.name}, I am {self.age} years old, and my current grade is {self.grade}.") + return f"Hello! I am {self.name}, I am {self.age} years old, and my current grade is {self.grade}." def study(self, hours): - print(f"{self.name} is studying for {hours} hours.") + return f"{self.name} is studying for {hours} hours." ### DON'T modify the code above ### @@ -22,13 +22,13 @@ def __init__(self, name, age, grade, major): self.major = major def introduce(self): - print(f"Hi there! I'm {self.name}, a college student majoring in {self.major}.") + return f"Hi there! I'm {self.name}, a college student majoring in {self.major}." def attend_lecture(self): - print(f"{self.name} is attending a lecture for {self.major} students.") + return f"{self.name} is attending a lecture for {self.major} students." college_student = CollegeStudent("Alice", 20, 90, "Computer Science") -college_student.introduce() -college_student.study(3) -college_student.attend_lecture() \ No newline at end of file +print(college_student.introduce()) +print(college_student.study(3)) +print(college_student.attend_lecture()) From e024286f0cc596436c2e1c4c9742c1c7823a90ba Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 24 Jan 2024 01:12:33 +0100 Subject: [PATCH 6/9] Update README.es.md --- exercises/043-inheritance_and_polymorphism/README.es.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/043-inheritance_and_polymorphism/README.es.md b/exercises/043-inheritance_and_polymorphism/README.es.md index 86e8efc0..455eaf0b 100644 --- a/exercises/043-inheritance_and_polymorphism/README.es.md +++ b/exercises/043-inheritance_and_polymorphism/README.es.md @@ -1,4 +1,4 @@ -# `043` inheritance and polymorphism +# `043` Inheritance and polymorphism Ahora que entendemos qué es una clase y algunas de sus características, hablemos sobre dos nuevos conceptos relacionados con las clases: herencia y polimorfismo. Considera el siguiente ejemplo: @@ -13,8 +13,8 @@ class HighSchoolStudent(Student): # Agrega la clase padre dentro de los parént # Creando una instancia de HighSchoolStudent high_school_student = HighSchoolStudent("John", 16, 85, "Science") -high_school_student.introduce() # Podemos llamar a este método gracias a la herencia -high_school_student.study(4) # Este método ha sido ligeramente modificado y ahora imprime un string diferente +print(high_school_student.introduce()) # Podemos llamar a este método gracias a la herencia +print(high_school_student.study(4)) # Este método ha sido ligeramente modificado y ahora retorna un string diferente ``` Suponiendo que la clase `Student` del ejercicio anterior está definida justo encima de esta clase `HighSchoolStudent`, para heredar sus métodos y atributos, simplemente incluimos el nombre de la clase que queremos heredar (la clase padre) dentro de los paréntesis de la clase hija (`HighSchoolStudent`). Como puedes ver, ahora podemos usar el método `introduce` de la clase `Student` sin tener que codificarlo nuevamente, haciendo nuestro código más eficiente. Lo mismo se aplica a los atributos; no necesitamos redefinirlos. From 7365bde47c6c8ae56e655159f5807f7543d36f8b Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 24 Jan 2024 01:13:21 +0100 Subject: [PATCH 7/9] Update README.md --- exercises/043-inheritance_and_polymorphism/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/exercises/043-inheritance_and_polymorphism/README.md b/exercises/043-inheritance_and_polymorphism/README.md index 15d313db..549f3cf3 100644 --- a/exercises/043-inheritance_and_polymorphism/README.md +++ b/exercises/043-inheritance_and_polymorphism/README.md @@ -1,4 +1,4 @@ -# `043` inheritance and polymorphism +# `043` Inheritance and polymorphism Now that we understand what a class is and some of its characteristics, let's talk about two new concepts related to classes: inheritance and polymorphism. Consider the following example: @@ -9,12 +9,12 @@ class HighSchoolStudent(Student): # Add the parent class inside the parenthesis self.specialization = specialization def study(self, hours): - print(f"{self.name} is a high school student specializing in {self.specialization} and is studying for {hours} hours for exams.") + return f"{self.name} is a high school student specializing in {self.specialization} and is studying for {hours} hours for exams." # Creating an instance of HighSchoolStudent high_school_student = HighSchoolStudent("John", 16, 85, "Science") -high_school_student.introduce() # We can call this method thanks to inheritance -high_school_student.study(4) # This method has been slightly modified and now it prints a different string +print(high_school_student.introduce()) # We can call this method thanks to inheritance +print(high_school_student.study(4)) # This method has been slightly modified and now it returns a different string ``` Assuming that the `Student` class from the previous exercise is coded just above this `HighSchoolStudent` class, to inherit its methods and attributes, we simply include the name of the class we want to inherit from (the parent class) inside the parentheses of the child class (`HighSchoolStudent`). As you can see, we can now use the `introduce` method from the `Student` class without having to code it again, making our code more efficient. The same applies to attributes; we don't need to redefine them. @@ -27,13 +27,13 @@ Additionally, we have the flexibility to add new methods exclusively for this cl 2. Add a new attribute called `major` to represent the major they are studying. -3. Modify the inherited `introduce` method to print this string: +3. Modify the inherited `introduce` method to return this string: ```py "Hi there! I'm , a college student majoring in ." ``` -4. Add a new method called `attend_lecture` that prints the following string: +4. Add a new method called `attend_lecture` that returns the following string: ```py " is attending a lecture for students." From 47e84386308466c8c1bc63c4af959daae525f36d Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 24 Jan 2024 03:14:12 +0100 Subject: [PATCH 8/9] Create test.py --- .../043-inheritance_and_polymorphism/test.py | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 exercises/043-inheritance_and_polymorphism/test.py diff --git a/exercises/043-inheritance_and_polymorphism/test.py b/exercises/043-inheritance_and_polymorphism/test.py new file mode 100644 index 00000000..e082627b --- /dev/null +++ b/exercises/043-inheritance_and_polymorphism/test.py @@ -0,0 +1,66 @@ +import pytest +from app import CollegeStudent + +@pytest.mark.it("The CollegeStudent class should exist") +def test_college_student_class_exists(): + try: + assert CollegeStudent + except AttributeError: + raise AttributeError("The class 'CollegeStudent' should exist in app.py") + +@pytest.mark.it("The CollegeStudent class includes the 'name' attribute") +def test_college_student_has_name_attribute(): + college_student = CollegeStudent("John", 21, 75, "Computer Science") + assert hasattr(college_student, "name") + +@pytest.mark.it("The CollegeStudent class includes the 'age' attribute") +def test_college_student_has_age_attribute(): + college_student = CollegeStudent("John", 21, 75, "Computer Science") + assert hasattr(college_student, "age") + +@pytest.mark.it("The CollegeStudent class includes the 'grade' attribute") +def test_college_student_has_grade_attribute(): + college_student = CollegeStudent("John", 21, 75, "Computer Science") + assert hasattr(college_student, "grade") + +@pytest.mark.it("The CollegeStudent class includes the 'major' attribute") +def test_college_student_has_major_attribute(): + college_student = CollegeStudent("John", 21, 75, "Computer Science") + assert hasattr(college_student, "major") + +@pytest.mark.it("The CollegeStudent class includes the 'introduce' method") +def test_college_student_has_introduce_method(): + college_student = CollegeStudent("Alice", 22, 90, "Computer Science") + assert hasattr(college_student, "introduce") + +@pytest.mark.it("The CollegeStudent class includes the 'study' method") +def test_college_student_has_study_method(): + college_student = CollegeStudent("John", 21, 75, "Computer Science") + assert hasattr(college_student, "study") + +@pytest.mark.it("The CollegeStudent class includes the 'attend_lecture' method") +def test_college_student_has_attend_lecture_method(): + college_student = CollegeStudent("John", 21, 75, "Computer Science") + assert hasattr(college_student, "attend_lecture") + +@pytest.mark.it("The introduce method should return the expected string. Testing with different values") +def test_college_student_introduce_method_returns_expected_string(): + student1 = CollegeStudent("Alice", 22, 90, "Computer Science") + student2 = CollegeStudent("Bob", 19, 85, "Mathematics") + assert student1.introduce() == "Hi there! I'm Alice, a college student majoring in Computer Science." + assert student2.introduce() == "Hi there! I'm Bob, a college student majoring in Mathematics." + +@pytest.mark.it("The study method should return the expected string. Testing with different values") +def test_college_student_study_method_returns_expected_string(): + student1 = CollegeStudent("Eve", 20, 78, "Physics") + student2 = CollegeStudent("Charlie", 23, 88, "Chemistry") + assert student1.study(3) == "Eve is studying for 3 hours." + assert student2.study(2) == "Charlie is studying for 2 hours." + +@pytest.mark.it("The attend_lecture method should return the expected string. Testing with different values") +def test_college_student_attend_lecture_method_returns_expected_string(): + student1 = CollegeStudent("Eve", 20, 78, "Physics") + student2 = CollegeStudent("Charlie", 23, 88, "Chemistry") + assert student1.attend_lecture() == "Eve is attending a lecture for Physics students." + assert student2.attend_lecture() == "Charlie is attending a lecture for Chemistry students." + From d5fdaff8e8e80c6824208098d0b9c0672d34b8f2 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 24 Jan 2024 04:29:18 +0100 Subject: [PATCH 9/9] Update app.py --- exercises/043-inheritance_and_polymorphism/app.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/exercises/043-inheritance_and_polymorphism/app.py b/exercises/043-inheritance_and_polymorphism/app.py index 2bff00cf..5f3c0b39 100644 --- a/exercises/043-inheritance_and_polymorphism/app.py +++ b/exercises/043-inheritance_and_polymorphism/app.py @@ -7,12 +7,11 @@ def __init__(self, name, age, grade): self.grade = grade def introduce(self): - print(f"Hello! I am {self.name}, I am {self.age} years old, and my current grade is {self.grade}.") + return f"Hello! I am {self.name}, I am {self.age} years old, and my current grade is {self.grade}." def study(self, hours): - print(f"{self.name} is studying for {hours} hours.") + return f"{self.name} is studying for {hours} hours." ### DON'T modify the code above ### ### ↓ Your code here ↓ ### -