From 58fe726db650698f4184918b2bbb43b0ef0046d4 Mon Sep 17 00:00:00 2001 From: sheida-shab Date: Tue, 2 Dec 2025 19:08:59 +0000 Subject: [PATCH 01/13] fixing the bugs in the code --- .gitignore | 2 ++ .vscode/settings.json | 4 ++++ sprint5-prep/prep2-exercise.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 sprint5-prep/prep2-exercise.py diff --git a/.gitignore b/.gitignore index 3c3629e6..59cc0d26 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules +/.venv +implement-cowsay/.venv/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..3a650214 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "python.analysis.typeCheckingMode": "basic", + "python.analysis.autoImportCompletions": true +} diff --git a/sprint5-prep/prep2-exercise.py b/sprint5-prep/prep2-exercise.py new file mode 100644 index 00000000..26c0c6e0 --- /dev/null +++ b/sprint5-prep/prep2-exercise.py @@ -0,0 +1,30 @@ +def open_account(balances, name, amount): + balances[name] = amount + +def sum_balances(accounts): + total = 0 + for name, pence in accounts.items(): + print(f"{name} had balance {pence}") + total += pence + return total + +def format_pence_as_string(total_pence): + if total_pence < 100: + return f"{total_pence}p" + pounds = int(total_pence / 100) + pence = total_pence % 100 + return f"£{pounds}.{pence:02d}" + +balances = { + "Sima": 700, + "Linn": 545, + "Georg": 831, +} + +open_account(balances,"Tobi", 913) +open_account(balances,"Olya", 713) + +total_pence = sum_balances(balances) +total_string = format_pence_as_string(total_pence) + +print(f"The bank accounts total {total_string}") \ No newline at end of file From 22e6770a6c3dc079389f16c56b01358ff9d20175 Mon Sep 17 00:00:00 2001 From: sheida-shab Date: Tue, 2 Dec 2025 19:22:29 +0000 Subject: [PATCH 02/13] fixing the bug and add a new function to show the bug related to a property that doesn't exist --- sprint5-prep/prep3-exercise.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 sprint5-prep/prep3-exercise.py diff --git a/sprint5-prep/prep3-exercise.py b/sprint5-prep/prep3-exercise.py new file mode 100644 index 00000000..538d2ebc --- /dev/null +++ b/sprint5-prep/prep3-exercise.py @@ -0,0 +1,21 @@ +class Person: + def __init__(self, name: str, age: int, preferred_operating_system: str): + self.name = name + self.age = age + self.preferred_operating_system = preferred_operating_system + +imran = Person("Imran", 22, "Ubuntu") +print(imran.name) + + +eliza = Person("Eliza", 34, "Arch Linux") +print(eliza.name) + +def is_adult(person: Person) -> bool: + return person.age >= 18 + +print(is_adult(imran)) + +def is_from_UK(person:Person) -> bool : + return person.country=="UK" +print(is_from_UK(eliza)) \ No newline at end of file From 801b1c36ca0eb664149571188c6cf343f1e7b93b Mon Sep 17 00:00:00 2001 From: sheida-shab Date: Tue, 2 Dec 2025 19:49:52 +0000 Subject: [PATCH 03/13] add types to prep2 & change class property and method --- sprint5-prep/prep2-exercise.py | 2 +- sprint5-prep/prep4-exercise.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 sprint5-prep/prep4-exercise.py diff --git a/sprint5-prep/prep2-exercise.py b/sprint5-prep/prep2-exercise.py index 26c0c6e0..8ced4112 100644 --- a/sprint5-prep/prep2-exercise.py +++ b/sprint5-prep/prep2-exercise.py @@ -1,4 +1,4 @@ -def open_account(balances, name, amount): +def open_account(balances: dict[str,int], name : str, amount:int): balances[name] = amount def sum_balances(accounts): diff --git a/sprint5-prep/prep4-exercise.py b/sprint5-prep/prep4-exercise.py new file mode 100644 index 00000000..32661d3e --- /dev/null +++ b/sprint5-prep/prep4-exercise.py @@ -0,0 +1,16 @@ +import datetime +class Person: + def __init__(self, name: str, date_of_birth : datetime.date, preferred_operating_system: str): + self.name = name + self.date_of_birth =date_of_birth + self.preferred_operating_system = preferred_operating_system + def is_adult(self): + today=datetime.date.today() + age=today.year-self.date_of_birth.year + print(age) + return age >= 18 + +imran = Person("Imran", datetime.date(1998,4,3), "Ubuntu") +print(imran.is_adult()) +eliza = Person("Eliza",datetime.date(2013,3,17), "Arch Linux") +print(eliza.is_adult()) \ No newline at end of file From 2fdc02c04e606f7b22fdce54f05a56a27a8250c0 Mon Sep 17 00:00:00 2001 From: sheida-shab Date: Tue, 2 Dec 2025 20:38:20 +0000 Subject: [PATCH 04/13] using @datatype& datetime.date & add the is_adult method --- sprint5-prep/prep5-exercise.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 sprint5-prep/prep5-exercise.py diff --git a/sprint5-prep/prep5-exercise.py b/sprint5-prep/prep5-exercise.py new file mode 100644 index 00000000..0e155fef --- /dev/null +++ b/sprint5-prep/prep5-exercise.py @@ -0,0 +1,17 @@ +from dataclasses import dataclass +import datetime +@dataclass(frozen=True) +class Person: + name: str + date_of_birth: datetime.date + preferred_operating_system: str + def is_adult(self) -> bool : + today=datetime.date.today() + age=today.year-self.date_of_birth.year + if(today.month,today.day)<(self.date_of_birth.month,self.date_of_birth.day) : + age -=1 + return age>=18 +imran = Person("Imran", datetime.date(2007,12,16), "Ubuntu") +print(imran) +print(imran.is_adult()) + From 1424f219749d8de71fd263e7350a666d2df3916f Mon Sep 17 00:00:00 2001 From: sheida-shab Date: Tue, 2 Dec 2025 20:52:07 +0000 Subject: [PATCH 05/13] fixing the bug and print family tree with children 's ages --- sprint5-prep/prep6-exercise.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 sprint5-prep/prep6-exercise.py diff --git a/sprint5-prep/prep6-exercise.py b/sprint5-prep/prep6-exercise.py new file mode 100644 index 00000000..0bb32d2b --- /dev/null +++ b/sprint5-prep/prep6-exercise.py @@ -0,0 +1,19 @@ +from dataclasses import dataclass +from typing import List + +@dataclass(frozen=True) +class Person: + name: str + age :int + children: List["Person"] +fatma = Person(name="Fatma",age=8, children=[]) +aisha = Person(name="Aisha",age=12, children=[]) + +imran = Person(name="Imran",age=40, children=[fatma, aisha]) + +def print_family_tree(person: Person) -> None: + print(person.name) + for child in person.children: + print(f"- {child.name} ({child.age})") + +print_family_tree(imran) \ No newline at end of file From eedfc309f1e310fa4577b8641a7b2213397f85d7 Mon Sep 17 00:00:00 2001 From: sheida-shab Date: Tue, 2 Dec 2025 21:02:01 +0000 Subject: [PATCH 06/13] canging data type from str to List[str] & fixed errors to make the code run --- sprint5-prep/prep7-exercise.py | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 sprint5-prep/prep7-exercise.py diff --git a/sprint5-prep/prep7-exercise.py b/sprint5-prep/prep7-exercise.py new file mode 100644 index 00000000..1d098e48 --- /dev/null +++ b/sprint5-prep/prep7-exercise.py @@ -0,0 +1,42 @@ +from dataclasses import dataclass +from typing import List + +@dataclass(frozen=True) +class Person: + name: str + age: int + preferred_operating_systems: List[str] + + +@dataclass(frozen=True) +class Laptop: + id: int + manufacturer: str + model: str + screen_size_in_inches: float + operating_system: str + + +def find_possible_laptops(laptops: List[Laptop], person: Person) -> List[Laptop]: + possible_laptops = [] + for laptop in laptops: + if laptop.operating_system in person.preferred_operating_systems: + possible_laptops.append(laptop) + return possible_laptops + + +people = [ + Person(name="Imran", age=22, preferred_operating_systems=["Ubuntu"]), + Person(name="Eliza", age=34, preferred_operating_systems=["Arch Linux"]), +] + +laptops = [ + Laptop(id=1, manufacturer="Dell", model="XPS", screen_size_in_inches=13, operating_system="Arch Linux"), + Laptop(id=2, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system="Ubuntu"), + Laptop(id=3, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system="ubuntu"), + Laptop(id=4, manufacturer="Apple", model="macBook", screen_size_in_inches=13, operating_system="macOS"), +] + +for person in people: + possible_laptops = find_possible_laptops(laptops, person) + print(f"Possible laptops for {person.name}: {possible_laptops}") \ No newline at end of file From dd973d214feb035562fd2df0632dada66ce1616d Mon Sep 17 00:00:00 2001 From: sheida-shab Date: Tue, 2 Dec 2025 22:07:51 +0000 Subject: [PATCH 07/13] code accepts user detail & tell how many laptops & which operating systems are avaialable --- sprint5-prep/prep8-exercise.py | 79 ++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 sprint5-prep/prep8-exercise.py diff --git a/sprint5-prep/prep8-exercise.py b/sprint5-prep/prep8-exercise.py new file mode 100644 index 00000000..ee3b2236 --- /dev/null +++ b/sprint5-prep/prep8-exercise.py @@ -0,0 +1,79 @@ +from dataclasses import dataclass +from enum import Enum +from typing import List +import sys +from collections import Counter + +class OperatingSystem(Enum): + MACOS = "macOS" + ARCH = "Arch Linux" + UBUNTU = "Ubuntu" + +@dataclass(frozen=True) +class Person: + name: str + age: int + preferred_operating_system: OperatingSystem + + +@dataclass(frozen=True) +class Laptop: + id: int + manufacturer: str + model: str + screen_size_in_inches: float + operating_system: OperatingSystem + +name=input("Insert your name :") +if len(name)==0 : + print("Name cannot be empty!", file=sys.stderr) + exit(1) +elif len(name)>50 : + print("Name is too long!", file=sys.stderr) + exit(1) +try : + age=int(input("Insert your age :")) + if age<18 or age>100 : + raise ValueError("Age out of range") +except ValueError as e : + print(f"Invalid age: {e}", file=sys.stderr) + sys.exit(1) +preferred_os=input("Insert your preferred_operating_system(macOS,Arch Linux,Ubuntu) :") +try : + preferred_operating_system=OperatingSystem(preferred_os) +except ValueError: + print("error in os name",file=sys.stderr) + sys.exit(1) + +person=Person(name,age,preferred_operating_system) + +def find_possible_laptops(laptops: List[Laptop], person: Person) -> List[Laptop]: + possible_laptops = [] + for laptop in laptops: + if laptop.operating_system == person.preferred_operating_system: + possible_laptops.append(laptop) + return possible_laptops + + +laptops = [ + Laptop(id=1, manufacturer="Dell", model="XPS", screen_size_in_inches=13, operating_system=OperatingSystem.ARCH), + Laptop(id=2, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system=OperatingSystem.UBUNTU), + Laptop(id=3, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system=OperatingSystem.UBUNTU), + Laptop(id=4, manufacturer="Apple", model="macBook", screen_size_in_inches=13, operating_system=OperatingSystem.MACOS), + Laptop(id=5, manufacturer="Dell", model="XPS", screen_size_in_inches=13, operating_system=OperatingSystem.ARCH), +] + +os_count=Counter(laptop.operating_system for laptop in laptops) +max_count=max(os_count.values()) +print(max_count) +most_available_os=[] +for os in os_count : + count=os_count[os] + if count==max_count : + most_available_os.append(os.value) +print(most_available_os) +possible_laptops = find_possible_laptops(laptops, person) +print(f"Count of available {person.preferred_operating_system.value} laptops for {person.name} is : {len(possible_laptops)}") + +if len(possible_laptops) Date: Wed, 3 Dec 2025 21:22:48 +0000 Subject: [PATCH 08/13] play computer with this code & debug & comment the lines which contain methodsthat don't exist in parent class --- sprint5-prep/prep9-exercise.py | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 sprint5-prep/prep9-exercise.py diff --git a/sprint5-prep/prep9-exercise.py b/sprint5-prep/prep9-exercise.py new file mode 100644 index 00000000..e11b5410 --- /dev/null +++ b/sprint5-prep/prep9-exercise.py @@ -0,0 +1,37 @@ +class Parent: + def __init__(self, first_name: str, last_name: str): + self.first_name = first_name + self.last_name = last_name + + def get_name(self) -> str: + return f"{self.first_name} {self.last_name}" + + +class Child(Parent): + def __init__(self, first_name: str, last_name: str): + super().__init__(first_name, last_name) + self.previous_last_names = [] + + def change_last_name(self, last_name) -> None: + self.previous_last_names.append(self.last_name) + self.last_name = last_name + + def get_full_name(self) -> str: + suffix = "" + if len(self.previous_last_names) > 0: + suffix = f" (née {self.previous_last_names[0]})" + return f"{self.first_name} {self.last_name}{suffix}" + +person1 = Child("Elizaveta", "Alekseeva") +print(person1.get_name()) +print(person1.get_full_name()) +person1.change_last_name("Tyurina") +print(person1.get_name()) +print(person1.get_full_name()) + +person2 = Parent("Elizaveta", "Alekseeva") +print(person2.get_name()) +# print(person2.get_full_name()) +# person2.change_last_name("Tyurina") +print(person2.get_name()) +# print(person2.get_full_name()) \ No newline at end of file From e79d308a6c75cd42b4effc348efc9e591bebf04d Mon Sep 17 00:00:00 2001 From: sheida-shab Date: Thu, 8 Jan 2026 15:58:22 +0000 Subject: [PATCH 09/13] added type hints to all functions --- sprint5-prep/prep2-exercise.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sprint5-prep/prep2-exercise.py b/sprint5-prep/prep2-exercise.py index 8ced4112..ba3f22dd 100644 --- a/sprint5-prep/prep2-exercise.py +++ b/sprint5-prep/prep2-exercise.py @@ -1,14 +1,14 @@ -def open_account(balances: dict[str,int], name : str, amount:int): +def open_account(balances: dict[str,int], name : str, amount:int) -> None: balances[name] = amount -def sum_balances(accounts): +def sum_balances(accounts : dict[str,int]) -> int: total = 0 for name, pence in accounts.items(): print(f"{name} had balance {pence}") total += pence return total -def format_pence_as_string(total_pence): +def format_pence_as_string(total_pence :int) -> str: if total_pence < 100: return f"{total_pence}p" pounds = int(total_pence / 100) From 579f83d3e09064b478af3eae09fbf5f3c0b13c8c Mon Sep 17 00:00:00 2001 From: sheida-shab Date: Thu, 8 Jan 2026 17:14:49 +0000 Subject: [PATCH 10/13] Format code with Black --- sprint5-prep/prep2-exercise.py | 15 +++--- sprint5-prep/prep3-exercise.py | 12 +++-- sprint5-prep/prep4-exercise.py | 20 ++++--- sprint5-prep/prep5-exercise.py | 25 +++++---- sprint5-prep/prep6-exercise.py | 15 ++++-- sprint5-prep/prep7-exercise.py | 35 +++++++++++-- sprint5-prep/prep8-exercise.py | 96 ++++++++++++++++++++++++---------- sprint5-prep/prep9-exercise.py | 3 +- 8 files changed, 157 insertions(+), 64 deletions(-) diff --git a/sprint5-prep/prep2-exercise.py b/sprint5-prep/prep2-exercise.py index ba3f22dd..885099af 100644 --- a/sprint5-prep/prep2-exercise.py +++ b/sprint5-prep/prep2-exercise.py @@ -1,30 +1,33 @@ -def open_account(balances: dict[str,int], name : str, amount:int) -> None: +def open_account(balances: dict[str, int], name: str, amount: int) -> None: balances[name] = amount -def sum_balances(accounts : dict[str,int]) -> int: + +def sum_balances(accounts: dict[str, int]) -> int: total = 0 for name, pence in accounts.items(): print(f"{name} had balance {pence}") total += pence return total -def format_pence_as_string(total_pence :int) -> str: + +def format_pence_as_string(total_pence: int) -> str: if total_pence < 100: return f"{total_pence}p" pounds = int(total_pence / 100) pence = total_pence % 100 return f"£{pounds}.{pence:02d}" + balances = { "Sima": 700, "Linn": 545, "Georg": 831, } -open_account(balances,"Tobi", 913) -open_account(balances,"Olya", 713) +open_account(balances, "Tobi", 913) +open_account(balances, "Olya", 713) total_pence = sum_balances(balances) total_string = format_pence_as_string(total_pence) -print(f"The bank accounts total {total_string}") \ No newline at end of file +print(f"The bank accounts total {total_string}") diff --git a/sprint5-prep/prep3-exercise.py b/sprint5-prep/prep3-exercise.py index 538d2ebc..9a72025e 100644 --- a/sprint5-prep/prep3-exercise.py +++ b/sprint5-prep/prep3-exercise.py @@ -4,6 +4,7 @@ def __init__(self, name: str, age: int, preferred_operating_system: str): self.age = age self.preferred_operating_system = preferred_operating_system + imran = Person("Imran", 22, "Ubuntu") print(imran.name) @@ -11,11 +12,16 @@ def __init__(self, name: str, age: int, preferred_operating_system: str): eliza = Person("Eliza", 34, "Arch Linux") print(eliza.name) + def is_adult(person: Person) -> bool: return person.age >= 18 + print(is_adult(imran)) -def is_from_UK(person:Person) -> bool : - return person.country=="UK" -print(is_from_UK(eliza)) \ No newline at end of file + +def is_from_UK(person: Person) -> bool: + return person.country == "UK" + + +print(is_from_UK(eliza)) diff --git a/sprint5-prep/prep4-exercise.py b/sprint5-prep/prep4-exercise.py index 32661d3e..51f2ee32 100644 --- a/sprint5-prep/prep4-exercise.py +++ b/sprint5-prep/prep4-exercise.py @@ -1,16 +1,22 @@ import datetime + + class Person: - def __init__(self, name: str, date_of_birth : datetime.date, preferred_operating_system: str): + def __init__( + self, name: str, date_of_birth: datetime.date, preferred_operating_system: str + ): self.name = name - self.date_of_birth =date_of_birth + self.date_of_birth = date_of_birth self.preferred_operating_system = preferred_operating_system + def is_adult(self): - today=datetime.date.today() - age=today.year-self.date_of_birth.year + today = datetime.date.today() + age = today.year - self.date_of_birth.year print(age) return age >= 18 -imran = Person("Imran", datetime.date(1998,4,3), "Ubuntu") + +imran = Person("Imran", datetime.date(1998, 4, 3), "Ubuntu") print(imran.is_adult()) -eliza = Person("Eliza",datetime.date(2013,3,17), "Arch Linux") -print(eliza.is_adult()) \ No newline at end of file +eliza = Person("Eliza", datetime.date(2013, 3, 17), "Arch Linux") +print(eliza.is_adult()) diff --git a/sprint5-prep/prep5-exercise.py b/sprint5-prep/prep5-exercise.py index 0e155fef..3766edeb 100644 --- a/sprint5-prep/prep5-exercise.py +++ b/sprint5-prep/prep5-exercise.py @@ -1,17 +1,24 @@ from dataclasses import dataclass import datetime + + @dataclass(frozen=True) class Person: name: str date_of_birth: datetime.date preferred_operating_system: str - def is_adult(self) -> bool : - today=datetime.date.today() - age=today.year-self.date_of_birth.year - if(today.month,today.day)<(self.date_of_birth.month,self.date_of_birth.day) : - age -=1 - return age>=18 -imran = Person("Imran", datetime.date(2007,12,16), "Ubuntu") -print(imran) -print(imran.is_adult()) + def is_adult(self) -> bool: + today = datetime.date.today() + age = today.year - self.date_of_birth.year + if (today.month, today.day) < ( + self.date_of_birth.month, + self.date_of_birth.day, + ): + age -= 1 + return age >= 18 + + +imran = Person("Imran", datetime.date(2007, 12, 16), "Ubuntu") +print(imran) +print(imran.is_adult()) diff --git a/sprint5-prep/prep6-exercise.py b/sprint5-prep/prep6-exercise.py index 0bb32d2b..ea02d922 100644 --- a/sprint5-prep/prep6-exercise.py +++ b/sprint5-prep/prep6-exercise.py @@ -1,19 +1,24 @@ from dataclasses import dataclass from typing import List + @dataclass(frozen=True) class Person: name: str - age :int + age: int children: List["Person"] -fatma = Person(name="Fatma",age=8, children=[]) -aisha = Person(name="Aisha",age=12, children=[]) -imran = Person(name="Imran",age=40, children=[fatma, aisha]) + +fatma = Person(name="Fatma", age=8, children=[]) +aisha = Person(name="Aisha", age=12, children=[]) + +imran = Person(name="Imran", age=40, children=[fatma, aisha]) + def print_family_tree(person: Person) -> None: print(person.name) for child in person.children: print(f"- {child.name} ({child.age})") -print_family_tree(imran) \ No newline at end of file + +print_family_tree(imran) diff --git a/sprint5-prep/prep7-exercise.py b/sprint5-prep/prep7-exercise.py index 1d098e48..7645f71c 100644 --- a/sprint5-prep/prep7-exercise.py +++ b/sprint5-prep/prep7-exercise.py @@ -1,6 +1,7 @@ from dataclasses import dataclass from typing import List + @dataclass(frozen=True) class Person: name: str @@ -31,12 +32,36 @@ def find_possible_laptops(laptops: List[Laptop], person: Person) -> List[Laptop] ] laptops = [ - Laptop(id=1, manufacturer="Dell", model="XPS", screen_size_in_inches=13, operating_system="Arch Linux"), - Laptop(id=2, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system="Ubuntu"), - Laptop(id=3, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system="ubuntu"), - Laptop(id=4, manufacturer="Apple", model="macBook", screen_size_in_inches=13, operating_system="macOS"), + Laptop( + id=1, + manufacturer="Dell", + model="XPS", + screen_size_in_inches=13, + operating_system="Arch Linux", + ), + Laptop( + id=2, + manufacturer="Dell", + model="XPS", + screen_size_in_inches=15, + operating_system="Ubuntu", + ), + Laptop( + id=3, + manufacturer="Dell", + model="XPS", + screen_size_in_inches=15, + operating_system="ubuntu", + ), + Laptop( + id=4, + manufacturer="Apple", + model="macBook", + screen_size_in_inches=13, + operating_system="macOS", + ), ] for person in people: possible_laptops = find_possible_laptops(laptops, person) - print(f"Possible laptops for {person.name}: {possible_laptops}") \ No newline at end of file + print(f"Possible laptops for {person.name}: {possible_laptops}") diff --git a/sprint5-prep/prep8-exercise.py b/sprint5-prep/prep8-exercise.py index ee3b2236..2c07c7aa 100644 --- a/sprint5-prep/prep8-exercise.py +++ b/sprint5-prep/prep8-exercise.py @@ -4,11 +4,13 @@ import sys from collections import Counter + class OperatingSystem(Enum): MACOS = "macOS" ARCH = "Arch Linux" UBUNTU = "Ubuntu" + @dataclass(frozen=True) class Person: name: str @@ -24,28 +26,32 @@ class Laptop: screen_size_in_inches: float operating_system: OperatingSystem -name=input("Insert your name :") -if len(name)==0 : + +name = input("Insert your name :") +if len(name) == 0: print("Name cannot be empty!", file=sys.stderr) exit(1) -elif len(name)>50 : - print("Name is too long!", file=sys.stderr) +elif len(name) > 50: + print("Name is too long!", file=sys.stderr) exit(1) -try : - age=int(input("Insert your age :")) - if age<18 or age>100 : +try: + age = int(input("Insert your age :")) + if age < 18 or age > 100: raise ValueError("Age out of range") -except ValueError as e : +except ValueError as e: print(f"Invalid age: {e}", file=sys.stderr) sys.exit(1) -preferred_os=input("Insert your preferred_operating_system(macOS,Arch Linux,Ubuntu) :") -try : - preferred_operating_system=OperatingSystem(preferred_os) +preferred_os = input( + "Insert your preferred_operating_system(macOS,Arch Linux,Ubuntu) :" +) +try: + preferred_operating_system = OperatingSystem(preferred_os) except ValueError: - print("error in os name",file=sys.stderr) + print("error in os name", file=sys.stderr) sys.exit(1) -person=Person(name,age,preferred_operating_system) +person = Person(name, age, preferred_operating_system) + def find_possible_laptops(laptops: List[Laptop], person: Person) -> List[Laptop]: possible_laptops = [] @@ -56,24 +62,58 @@ def find_possible_laptops(laptops: List[Laptop], person: Person) -> List[Laptop] laptops = [ - Laptop(id=1, manufacturer="Dell", model="XPS", screen_size_in_inches=13, operating_system=OperatingSystem.ARCH), - Laptop(id=2, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system=OperatingSystem.UBUNTU), - Laptop(id=3, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system=OperatingSystem.UBUNTU), - Laptop(id=4, manufacturer="Apple", model="macBook", screen_size_in_inches=13, operating_system=OperatingSystem.MACOS), - Laptop(id=5, manufacturer="Dell", model="XPS", screen_size_in_inches=13, operating_system=OperatingSystem.ARCH), + Laptop( + id=1, + manufacturer="Dell", + model="XPS", + screen_size_in_inches=13, + operating_system=OperatingSystem.ARCH, + ), + Laptop( + id=2, + manufacturer="Dell", + model="XPS", + screen_size_in_inches=15, + operating_system=OperatingSystem.UBUNTU, + ), + Laptop( + id=3, + manufacturer="Dell", + model="XPS", + screen_size_in_inches=15, + operating_system=OperatingSystem.UBUNTU, + ), + Laptop( + id=4, + manufacturer="Apple", + model="macBook", + screen_size_in_inches=13, + operating_system=OperatingSystem.MACOS, + ), + Laptop( + id=5, + manufacturer="Dell", + model="XPS", + screen_size_in_inches=13, + operating_system=OperatingSystem.ARCH, + ), ] -os_count=Counter(laptop.operating_system for laptop in laptops) -max_count=max(os_count.values()) +os_count = Counter(laptop.operating_system for laptop in laptops) +max_count = max(os_count.values()) print(max_count) -most_available_os=[] -for os in os_count : - count=os_count[os] - if count==max_count : - most_available_os.append(os.value) +most_available_os = [] +for os in os_count: + count = os_count[os] + if count == max_count: + most_available_os.append(os.value) print(most_available_os) possible_laptops = find_possible_laptops(laptops, person) -print(f"Count of available {person.preferred_operating_system.value} laptops for {person.name} is : {len(possible_laptops)}") +print( + f"Count of available {person.preferred_operating_system.value} laptops for {person.name} is : {len(possible_laptops)}" +) -if len(possible_laptops) str: suffix = f" (née {self.previous_last_names[0]})" return f"{self.first_name} {self.last_name}{suffix}" + person1 = Child("Elizaveta", "Alekseeva") print(person1.get_name()) print(person1.get_full_name()) @@ -34,4 +35,4 @@ def get_full_name(self) -> str: # print(person2.get_full_name()) # person2.change_last_name("Tyurina") print(person2.get_name()) -# print(person2.get_full_name()) \ No newline at end of file +# print(person2.get_full_name()) From 2cd708e40b8d76df7ea44c310532694da64c8379 Mon Sep 17 00:00:00 2001 From: sheida-shab Date: Thu, 8 Jan 2026 20:41:50 +0000 Subject: [PATCH 11/13] Improve clarity of printed results --- sprint5-prep/prep8-exercise.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sprint5-prep/prep8-exercise.py b/sprint5-prep/prep8-exercise.py index 2c07c7aa..852ee06b 100644 --- a/sprint5-prep/prep8-exercise.py +++ b/sprint5-prep/prep8-exercise.py @@ -101,18 +101,25 @@ def find_possible_laptops(laptops: List[Laptop], person: Person) -> List[Laptop] os_count = Counter(laptop.operating_system for laptop in laptops) max_count = max(os_count.values()) -print(max_count) + +print(f"\nHello {person.name}, here is the laptop availability info:") +print(f"You have requested: {person.preferred_operating_system.value}") + +# print(max_count) most_available_os = [] for os in os_count: count = os_count[os] if count == max_count: most_available_os.append(os.value) -print(most_available_os) +# print(most_available_os) possible_laptops = find_possible_laptops(laptops, person) print( - f"Count of available {person.preferred_operating_system.value} laptops for {person.name} is : {len(possible_laptops)}" + f"Count of available {person.preferred_operating_system.value} laptops for you is : {len(possible_laptops)}" ) +formatted_os = [f"{os.value} {os_count[os]}" for os in os_count if os_count[os] == max_count] +print(f"Most available operating systems: {', '.join(formatted_os)}") + if len(possible_laptops) < max_count: print( f"Note: If you are willing to accept : {" or ".join(most_available_os)}, you are more likely to get a laptop." From 203148c3a173641d11cf605aa8e0554c90ab75da Mon Sep 17 00:00:00 2001 From: sheida-shab Date: Thu, 8 Jan 2026 20:58:39 +0000 Subject: [PATCH 12/13] Fix var type annotation --- sprint5-prep/prep9-exercise.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sprint5-prep/prep9-exercise.py b/sprint5-prep/prep9-exercise.py index 8e2eb4f6..e9bd3fb7 100644 --- a/sprint5-prep/prep9-exercise.py +++ b/sprint5-prep/prep9-exercise.py @@ -10,7 +10,7 @@ def get_name(self) -> str: class Child(Parent): def __init__(self, first_name: str, last_name: str): super().__init__(first_name, last_name) - self.previous_last_names = [] + self.previous_last_names: list[str] = [] def change_last_name(self, last_name) -> None: self.previous_last_names.append(self.last_name) From 7e5cb38b1d74159841ac40d4ddef54dafdca09b4 Mon Sep 17 00:00:00 2001 From: sheida-shab Date: Mon, 12 Jan 2026 13:28:44 +0000 Subject: [PATCH 13/13] Increase upper level for adult age --- sprint5-prep/prep8-exercise.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sprint5-prep/prep8-exercise.py b/sprint5-prep/prep8-exercise.py index 852ee06b..144b0e9e 100644 --- a/sprint5-prep/prep8-exercise.py +++ b/sprint5-prep/prep8-exercise.py @@ -36,7 +36,7 @@ class Laptop: exit(1) try: age = int(input("Insert your age :")) - if age < 18 or age > 100: + if age < 18 or age > 150: raise ValueError("Age out of range") except ValueError as e: print(f"Invalid age: {e}", file=sys.stderr)