Educational Python implementation demonstrating class vs instance variables and basic OOP logic.
https://github.com/davidbmar/classVsInstance · public · shipped
A Python coding challenge solution that defines a Person class to manage age validation, state progression over time, and categorical status reporting (young, teenager, old). It serves as a practical example of object-oriented principles, specifically distinguishing between class-level and instance-level data and behavior.
python person.py
flowchart TD
A[Main Driver] -->|Input Age| B(Person Constructor)
B -->|Validate Age| C{Age < 0?}
C -->|Yes| D[Set Age = 0]
C -->|No| E[Set Age = Input]
D --> F[Print Warning]
E --> G[Store Instance Variable]
F --> H[Person Instance]
G --> H
H -->|Call| I[amIOld]
H -->|Call| J[yearPasses]
I --> K[Print Status]
J --> L[Increment Age]
The project consists of a single Python module defining a `Person` class. The class includes an `__init__` constructor for validation, a `yearPasses` method to mutate state, and an `amIOld` method for conditional output. It relies on standard Python control flow and print statements, designed to interface with a provided stub/main driver for testing.
sequenceDiagram
participant Main as Main Driver
participant P as Person Instance
Main->>P: __init__(initialAge)
alt initialAge < 0
P->>P: self.age = 0
P->>Main: Print 'Age is not valid...'
else initialAge >= 0
P->>P: self.age = initialAge
end
Main->>P: amIOld()
P->>Main: Print Status (Young/Teen/Old)
Main->>P: yearPasses()
P->>P: self.age += 1
Main->>P: amIOld()
P->>Main: Print Updated Status
Integrate the `Person` class into Python learning modules, OOP tutorials, or automated grading systems for introductory programming courses. Use it as a reference for implementing validation logic within constructors and managing object state transitions.
✓ all on main — nothing unmerged.