๐Ÿ”ฅ TCS PRA Python Question – Employee Loan Eligibility System (Full Question + Solution)

TCS PRA Python Employee loan eligibility question with full solution, OOP concepts, logic explanation and code practice.
If you're preparing for TCS PRA (Project Readiness Assessment), this is a high-level Python OOP-based problem focusing on real-world logic like loan eligibility and organization management.

In this article, you’ll find:

  • ✅ Full question (as it is)
  • ✅ Simple explanation
  • ✅ Complete Python solution

๐Ÿ“„ Full Question (As Given in Exam)

Write the code to define a class to create Employee objects with the below attributes :

Name
designation
salary
Loan details (stores the details of different types of loans employee has taken along with the amount borrowed for a loan type as key : value pairs - loan type : borrowed amount).

Define the method in the class which takes as argument values for all attributes in the above sequence and set the value of attributes to parameter values while creating an Employee object.

Write the code to define a class to create an Organization object with the below attributes :

1. A list of Employee objects
2. A list of types of loans Organization offers to employees
3. Designation wise eligible maximum loan amount stored as key : value pairs - designation : maximum eligible loan amount.

Define a method which takes as argument value of the attribute and initialize the attribute with the given value while creating an Organization object.

Define another two methods inside the Organization class as described below :

A. A method to check if an employee is eligible to take a loan or not.

Method takes arguments:
1. Employee name
2. Loan type
3. Loan amount

Conditions:
- Employee must exist
- Loan type should not be already taken
- Loan type must exist in organization loan list
- Total loan should not exceed max eligible loan for designation

If all conditions satisfied → return True and update loan details  
Else → return False

B. A method to return designation-wise count of employees still eligible for loans.

Note:
- Case insensitive search
- No duplicate employee names

(Full input/output instructions same as exam format)

๐Ÿง  Simple Explanation

  • ๐Ÿ‘‰ Create Employee class with loan tracking
  • ๐Ÿ‘‰ Create Organization class to manage employees
  • ๐Ÿ‘‰ Check loan eligibility based on conditions
  • ๐Ÿ‘‰ Calculate remaining eligible employees per designation

๐Ÿ’ป Python Solution Code

class Employee:
    def __init__(self, name, designation, salary, loanDetails):
        self.name = name
        self.designation = designation
        self.salary = salary
        self.loanDetails = loanDetails


class Organization:
    def __init__(self, empList, loanTypes, maxLoan):
        self.empList = empList
        self.loanTypes = loanTypes
        self.maxLoan = maxLoan

    def checkLoanEligibility(self, name, loanType, amount):
        for emp in self.empList:
            if emp.name.lower() == name.lower():

                if loanType in emp.loanDetails:
                    return False

                if loanType not in self.loanTypes:
                    return False

                totalLoan = sum(emp.loanDetails.values())

                maxEligible = self.maxLoan.get(emp.designation, 0)

                if totalLoan + amount > maxEligible:
                    return False

                emp.loanDetails[loanType] = amount
                return True

        return False

    def countEligibleEmployees(self):
        result = {}

        for emp in self.empList:
            totalLoan = sum(emp.loanDetails.values())
            maxEligible = self.maxLoan.get(emp.designation, 0)

            if emp.designation not in result:
                result[emp.designation] = 0

            if totalLoan < maxEligible:
                result[emp.designation] += 1

        return result


# MAIN PROGRAM

n = int(input())
empList = []

for _ in range(n):
    name = input()
    designation = input()
    salary = float(input())

    loanCount = int(input())
    loanDetails = {}

    for _ in range(loanCount):
        loanType = input()
        amount = float(input())
        loanDetails[loanType] = amount

    empList.append(Employee(name, designation, salary, loanDetails))


loanTypeCount = int(input())
loanTypes = [input() for _ in range(loanTypeCount)]


maxLoanCount = int(input())
maxLoan = {}

for _ in range(maxLoanCount):
    des = input()
    amt = float(input())
    maxLoan[des] = amt


org = Organization(empList, loanTypes, maxLoan)


name = input()
loanType = input()
amount = float(input())

if org.checkLoanEligibility(name, loanType, amount):
    print("Loan granted .")
    for k, v in next(emp.loanDetails for emp in empList if emp.name.lower() == name.lower()).items():
        print(k, ":", int(v))
else:
    print("Loan not granted")


result = org.countEligibleEmployees()

for k, v in result.items():
    print(k, ":", v)

๐ŸŽฏ Key Concepts Covered

  • ✔ Advanced OOP in Python
  • ✔ Dictionary handling
  • ✔ Conditional logic
  • ✔ Case-insensitive search
  • ✔ Real-world problem solving

๐Ÿš€ Final Tips

This is a high-level TCS PRA problem. Focus on logic building and condition handling.

Practice similar real-world scenarios to crack TCS easily ๐Ÿ”ฅ

Stay connected with JustNK.in for more coding questions and job updates.

Post a Comment

Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.