Skip to content

West Midlands | 26 March SDC | Iswat Bello | Sprint 5 | prep exercises for Object-Oriented Programming and Type safety#509

Open
Iswanna wants to merge 16 commits intoCodeYourFuture:mainfrom
Iswanna:tools/sprint5-prep-exercises
Open

West Midlands | 26 March SDC | Iswat Bello | Sprint 5 | prep exercises for Object-Oriented Programming and Type safety#509
Iswanna wants to merge 16 commits intoCodeYourFuture:mainfrom
Iswanna:tools/sprint5-prep-exercises

Conversation

@Iswanna
Copy link
Copy Markdown

@Iswanna Iswanna commented Apr 22, 2026

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Complete implementation of 12 preparatory exercises covering Python fundamentals, including classes, inheritance, type hints, generics, and enums.

What's New

  • 12 new Python exercise files demonstrating OOP concepts
  • Type-safe implementations using dataclasses and enums
  • Interactive user input examples

Files Changed

  • Added 11 .py exercise files
  • Added 1 .md documentation file

All Tests Pass ✓

  • mypy type checking: PASS
  • Runtime execution: PASS

Iswanna added 16 commits April 11, 2026 16:12
- Add .venv to ignore Python virtual environments
- Add *.class to ignore Java compiled class files
- Add exercise demonstrating the importance of type hints
- Include buggy double() function that multiplies by 3 instead of 2
- Document the bug and propose two possible fixes
- Create exercise file demonstrating why type hints matter
- Include half(), double(), and second() functions
- Add example showing string multiplication vs numeric multiplication
- Document expected behavior: double("22") returns "2222" due to string repetition
- Include question and answer explaining the type-dependent behavior
- Fix open_account() parameter: change 'balance' to 'balances' (NameError bug)
- Add missing type annotations to all function parameters and return types
- Run through mypy to validate all type hints are correct
- Verify code runs without errors
- Create Person class with type-annotated __init__ method
- Add name (str), age (int), and preferred_operating_system (str) attributes
- Create example instances (imran and eliza)
- Intentionally access undefined 'address' attribute to demonstrate mypy error detection
- Document the mypy error and explain the missing attribute issue
- Create Person class with type-annotated __init__ method
- Add name (str), age (int), and preferred_operating_system (str) attributes
- Implement is_adult() function that correctly accesses Person.age attribute
- Add is_adult_wrong_attribute() function that intentionally accesses non-existent Person.address
- Demonstrate mypy error detection for invalid attribute access
- Show how mypy validates correct vs incorrect property references
- Replace age (int) parameter with date_of_birth (datetime.date)
- Convert is_adult() from free function to instance method
- Implement dynamic age calculation based on current date
- Account for whether birthday has occurred this year
- Add type hints for all parameters and return types
- Include example usage with imran and eliza instances
- Create Person class with @DataClass(frozen=True) decorator
- Use datetime.date for date_of_birth instead of int for age
- Replace manual __init__ with declarative field definitions
- Implement is_adult() method with dynamic age calculation
- Account for whether birthday has occurred this year
- Add type hints for all attributes and methods
- Include example usage with imran and eliza instances
- Demonstrate immutable dataclass with frozen=True
- Create Person dataclass with @DataClass(frozen=True) decorator
- Use List["Person"] generic type for children attribute (self-referencing)
- Implement age() method that calculates age from date_of_birth
- Add example Person instances: fatma, aisha, and imran
- Implement print_family_tree() function to display family hierarchy
- Demonstrate practical use of generics for type-safe collections
- Show how mypy validates generic type parameters
…types

- Change Person.preferred_operating_system from str to List[str]
- Rename field to preferred_operating_systems (plural)
- Update find_possible_laptops() to check if OS is in list using 'in' operator
- Add example Person instances with multiple preferred operating systems
- Add sample Laptop instances for testing
- Demonstrate practical use of generic List types with dataclasses
- Run through mypy to validate all type annotations are correct
…enums

- Create OperatingSystem Enum with MACOS, ARCH, and UBUNTU values
- Define Person dataclass with preferred_operating_system as Enum type
- Define Laptop dataclass with operating_system as Enum type
- Implement find_possible_laptops() function to match laptops to person preferences
- Add library inventory: 4 sample laptops with different operating systems
- Add sample people with OS preferences
- Demonstrate type-safe enum usage vs string-based approach
- Display matching laptops for each person
- Add create_person_from_input() function for interactive person creation
- Prompt user for name, age, and preferred operating system
- Display available OS options from OperatingSystem Enum
- Validate user input with try/except for invalid OS choices
- Create Person instance and find matching laptops
- Display matching laptops for newly created person
- Maintain existing hardcoded people and laptop matching
- Add interactive section at end to test user input functionality
- Add newline before possible laptops output for better readability
- Add summary message showing count of available laptops
- Display the operating system name using enum.value property
- Improve user feedback with clearer output format
@Iswanna Iswanna added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 5 Assigned during Week 5 of this module Module-Tools The name of the module. labels Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Tools The name of the module. Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 5 Assigned during Week 5 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant