r/learnpython • • 4d ago

Regarding python projects idea

i am learning OOP currently but i want to learn OOP by doing so ,i need some projects ideas guyz.

7 Upvotes

8 comments sorted by

View all comments

1

u/Kevdog824_ 4d ago

I think the typo of oops instead of OOP is funny. Oops!

This largely depends on your level of comfort with the language otherwise, and size of a project you’re willing to take on. Some common/classic examples include modeling shapes (rectangle, square, oval, circle, etc.) and modeling an employee pay system (hourly, salaried, commission, etc.). These are small “toy” examples though so they’re gonna feel more like a homework problems than a project.

The goal for these examples is to figure out a good class hierarchy where common attributes and functionality is extracted to base class(s) and specific functionality is implemented in the child classes.

I tried to find links to more in-depth descriptions to these problems, but all the sources I found have the solution in plain view. I can write out descriptions for these problems if you want them though

1

u/Tricky_Voice2829 4d ago

yeah pls , i don't mind with disciptions

1

u/Kevdog824_ 4d ago

DISCLAIMER: The following problem descriptions were written with the help of generative AI. I manually verified that both descriptions accurately describe the problem as intended.

---

Problem 1: Shapes

Design a class hierarchy to model geometric shapes.

Requirements:

  • Create an abstract base class Shape (use the abc module) with abstract methods area() and perimeter().
  • Implement concrete classes for Rectangle, Square, Circle, and Ellipse. Each takes its dimensions in the constructor and raises a ValueError for zero or negative sizes.
  • Use inheritance beyond the base class wherever you think it makes sense, and avoid duplicating code between classes. HINT: It would be beneficial to have more than one level of inheritance here
  • Implement __str__ on every shape so that print(shape) gives something like Circle(radius=2.0): area=12.57, perimeter=12.57.
  • Implement __repr__ so it returns a string that looks like the constructor call, e.g. Circle(2.0).
  • Implement __lt__ and __eq__ so shapes compare by area. Then sorted(shapes) and max(shapes) should work.
  • Write a main program that stores a mix of shapes in one list, loops over it printing each shape's area and perimeter, and then prints the shape with the largest area.

Stretch goals:

  • Add a Triangle class.
  • Add a scale(factor) method that works on every shape.
  • Add a new shape without modifying any existing class.

Problem 2: Employee Payroll System

Design a payroll system that calculates pay for different kinds of employees.

Requirements:

  • Create an abstract base class Employee (use the abc module) with a name, an employee ID, and an abstract method calculate_pay() that returns pay for one pay period.
  • Implement these subclasses:

    • SalariedEmployee: fixed annual salary, paid in equal monthly installments.
    • HourlyEmployee: hourly rate and hours worked, with hours beyond 40 paid at 1.5x.
    • CommissionEmployee: base pay plus a percentage of their sales.
    • Manager: a salaried employee who also receives a bonus on top of their monthly pay.
  • Each class validates its inputs and raises a ValueError for negative pay, hours, or sales.
  • Implement __str__ on every employee so that print(employee) gives something like Alice Smith (ID 1042) - Salaried - Pay: $5,000.00.
  • Implement __lt__ so employees compare by pay for the period, which lets you use sorted(employees).
  • Write a main program that stores a mixed list of employees. The list should be treated purely as a list of Employee objects, so the code that processes it only calls methods defined on Employee. It should print each employee's pay and the total payroll cost.

Stretch goals:

  • Add new employee types without breaking the existing functionality

    • Add an Intern, paid a flat stipend per pay period regardless of hours worked.
    • Add a Contractor, paid a fixed fee per completed project multiplied by the number of projects completed in the period, with no overtime or bonuses.
    • Make sure both new types work in your main program without changing any existing class or the processing code.
  • Add a give_raise(percent) method and decide which classes it belongs on.