From c1c307cbffeaedd76b4c242579b4d7d2964d2759 Mon Sep 17 00:00:00 2001 From: Faithy4444 <161722786+Faithy4444@users.noreply.github.com> Date: Sat, 25 Oct 2025 21:35:54 +0200 Subject: [PATCH] sprint 4 prep exercises --- prep_exercises_sprint_4/enums.py | 89 ++++++++++++++++++++++++++ prep_exercises_sprint_4/inheritence.py | 37 +++++++++++ 2 files changed, 126 insertions(+) create mode 100644 prep_exercises_sprint_4/enums.py create mode 100644 prep_exercises_sprint_4/inheritence.py diff --git a/prep_exercises_sprint_4/enums.py b/prep_exercises_sprint_4/enums.py new file mode 100644 index 0000000..880823d --- /dev/null +++ b/prep_exercises_sprint_4/enums.py @@ -0,0 +1,89 @@ +from enum import Enum +import sys + +# Define the possible operating systems as an enum +class OperatingSystem(Enum): + MACOS = "MacOS" + ARCH = "Arch" + UBUNTU = "Ubuntu" + +# List of laptops available in the library +laptops = [ + {"id": 1, "manufacturer": "Dell", "model": "XPS", "os": OperatingSystem.ARCH}, + {"id": 2, "manufacturer": "Dell", "model": "XPS", "os": OperatingSystem.UBUNTU}, + {"id": 3, "manufacturer": "Dell", "model": "XPS", "os": OperatingSystem.UBUNTU}, + {"id": 4, "manufacturer": "Apple", "model": "MacBook", "os": OperatingSystem.MACOS}, + {"id": 5, "manufacturer": "Dell", "model": "Inspiron", "os": OperatingSystem.UBUNTU}, +] + +def get_user_preferences(): + """Get the user's name and preferred operating system""" + name = input("Enter your name: ").strip() + if not name: + print("Error: Name cannot be empty", file=sys.stderr) + sys.exit(1) + + print("\nAvailable operating systems:") + print("• MacOS") + print("• Arch") + print("• Ubuntu") + + os_choice = input("Enter your preferred operating system: ").strip().lower() + + # Convert string to OperatingSystem enum + if os_choice == "macos": + return name, OperatingSystem.MACOS + elif os_choice == "arch": + return name, OperatingSystem.ARCH + elif os_choice == "ubuntu": + return name, OperatingSystem.UBUNTU + else: + print(f"Error: '{os_choice}' is not a valid operating system", file=sys.stderr) + print("Please choose from: macos, arch, ubuntu", file=sys.stderr) + sys.exit(1) + +def count_laptops_by_os(): + """Count how many laptops we have for each operating system""" + counts = {} + for os in OperatingSystem: + counts[os] = 0 + + for laptop in laptops: + counts[laptop["os"]] += 1 + + return counts + +def main(): + print("=== Library Laptop Finder ===") + + # Get user input + name, preferred_os = get_user_preferences() + + # Count laptops for each OS + os_counts = count_laptops_by_os() + + # Show results to user + user_laptop_count = os_counts[preferred_os] + + print(f"\nHello {name}!") + print(f"We have {user_laptop_count} laptop(s) with {preferred_os.value}.") + + # Check if other OS have more laptops + other_options = [] + for os, count in os_counts.items(): + if os != preferred_os and count > user_laptop_count: + other_options.append((os, count)) + + if other_options: + print("\nTip: These operating systems have more laptops available:") + for os, count in other_options: + print(f" • {os.value}: {count} laptops") + + # Show complete availability + print(f"\nAll available laptops:") + for os in OperatingSystem: + count = os_counts[os] + print(f" • {os.value}: {count} laptop(s)") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/prep_exercises_sprint_4/inheritence.py b/prep_exercises_sprint_4/inheritence.py new file mode 100644 index 0000000..e11b541 --- /dev/null +++ b/prep_exercises_sprint_4/inheritence.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