From 293ff5757bd8426329e6fc0850c9788563f8944e Mon Sep 17 00:00:00 2001 From: Ira Date: Fri, 14 Jun 2024 14:20:37 +0300 Subject: [PATCH 1/2] Solution --- README.md | 2 +- app/main.py | 49 +++++++++++++++++++++++++++++++++++++++++++++- tests/test_main.py | 3 +-- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e94ea4cd..e9bde8ed 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ takes a `skill` of string type and should add it to the `skills` list. ```python engineer = SoftwareEngineer("Max") # engineer.skills == [] -engineer.learn_skill("Python") +learn_skill("Python") # engineer.skills == ["Python"] ``` diff --git a/app/main.py b/app/main.py index fa56336e..c162963c 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,48 @@ -# write your code here +class SoftwareEngineer: + def __init__(self, name: str): + self.name = name + self.skills = [] + + def learn_skill(self, skill: str) -> None: + self.skills.append(skill) + +class FrontendDeveloper(SoftwareEngineer): + def __init__(self, name: str) -> None: + super().__init__(name) + self.skills = ["JavaScript", "HTML", "CSS"] + + def create_awesome_web_page(self) -> str: + print(f"{self.name} is creating a webpage...") + return "

Hello world

" + +class BackendDeveloper(SoftwareEngineer): + def __init__(self, name: str): + super().__init__(name) + self.skills = ["Python", "SQL", "Django"] + + def create_powerful_api(self) -> str: + print(f"{self.name} is creating an API...") + return "http://127.0.0.1:8000" + +class AndroidDeveloper(SoftwareEngineer): + def __init__(self, name: str) -> None: + super().__init__(name) + self.skills = ["Java", "Android studio"] + + def create_smooth_mobile_app(self) -> str: + print(f"{self.name} is creating a mobile app...") + return "Ads every three swipes" + + +class FullStackDeveloper(BackendDeveloper, FrontendDeveloper): + def __init__(self, name: str): + BackendDeveloper.__init__(self, name) + FrontendDeveloper.__init__(self, name) + self.skills = list(dict.fromkeys(self.skills)) + + def create_web_application(self) -> None: + print(f"{self.name} started creating a web application...") + api_address = self.create_powerful_api() + webpage_code = self.create_awesome_web_page() + print(api_address) + print(webpage_code) diff --git a/tests/test_main.py b/tests/test_main.py index 4549d3c4..adef9c9a 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -123,7 +123,6 @@ def test_create_web_application_method(engineer, printed_messages): @pytest.mark.parametrize( - "function,result", [ ( SoftwareEngineer.__init__, @@ -131,7 +130,7 @@ def test_create_web_application_method(engineer, printed_messages): "return": type(None)} ), ( - SoftwareEngineer.learn_skill, + learn_skill, {"skill": str, "return": type(None)} ), From 1896cf1567bea160e0f07cf153bc7884028d15a0 Mon Sep 17 00:00:00 2001 From: Ira Date: Thu, 31 Oct 2024 12:40:17 +0200 Subject: [PATCH 2/2] Solution --- app/main.py | 25 +++++++++++-------------- tests/test_main.py | 3 ++- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/app/main.py b/app/main.py index c162963c..9b173619 100644 --- a/app/main.py +++ b/app/main.py @@ -1,48 +1,45 @@ class SoftwareEngineer: - def __init__(self, name: str): + def __init__(self, name: str) -> None: self.name = name self.skills = [] def learn_skill(self, skill: str) -> None: self.skills.append(skill) + class FrontendDeveloper(SoftwareEngineer): def __init__(self, name: str) -> None: super().__init__(name) - self.skills = ["JavaScript", "HTML", "CSS"] + self.skills.extend(["JavaScript", "HTML", "CSS"]) def create_awesome_web_page(self) -> str: print(f"{self.name} is creating a webpage...") return "

Hello world

" + class BackendDeveloper(SoftwareEngineer): - def __init__(self, name: str): + def __init__(self, name: str) -> None: super().__init__(name) - self.skills = ["Python", "SQL", "Django"] + self.skills += ["Python", "SQL", "Django"] def create_powerful_api(self) -> str: print(f"{self.name} is creating an API...") return "http://127.0.0.1:8000" + class AndroidDeveloper(SoftwareEngineer): def __init__(self, name: str) -> None: super().__init__(name) - self.skills = ["Java", "Android studio"] + self.skills.extend(["Java", "Android studio"]) def create_smooth_mobile_app(self) -> str: print(f"{self.name} is creating a mobile app...") return "Ads every three swipes" -class FullStackDeveloper(BackendDeveloper, FrontendDeveloper): - def __init__(self, name: str): - BackendDeveloper.__init__(self, name) - FrontendDeveloper.__init__(self, name) - self.skills = list(dict.fromkeys(self.skills)) +class FullStackDeveloper(FrontendDeveloper, BackendDeveloper): def create_web_application(self) -> None: print(f"{self.name} started creating a web application...") - api_address = self.create_powerful_api() - webpage_code = self.create_awesome_web_page() - print(api_address) - print(webpage_code) + self.create_powerful_api() + self.create_awesome_web_page() diff --git a/tests/test_main.py b/tests/test_main.py index adef9c9a..4549d3c4 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -123,6 +123,7 @@ def test_create_web_application_method(engineer, printed_messages): @pytest.mark.parametrize( + "function,result", [ ( SoftwareEngineer.__init__, @@ -130,7 +131,7 @@ def test_create_web_application_method(engineer, printed_messages): "return": type(None)} ), ( - learn_skill, + SoftwareEngineer.learn_skill, {"skill": str, "return": type(None)} ),