payslip python program TCS IPA | CPA

 TCS cpa / ipa questions and answers with explanation


program number 1


Create a class Payslip having attributes basicSalary,hra and ita.


Create a class PaySlipDemo containing a method getHighestPF with takes list of payslip objects and return the highest PF among the objects.PF should be 12% of basic salary


input:


2


10000


2000


1000


50000


3000


2000


output:


6000


ANSWER :


class Payslip:

  def __init__(self,bs,h,t):

    self.bs=bs

    self.h=h

    self.t=t

class Pd:

  def __init__(self):

    self.a=10

  def getpf(self,l):

    k=[]

    for i in l:

        a=i.bs*0.12

        k.append(a)

    k1=max(k)

    return int(k1)

if __name__==’__main__’:

  p=[]

  c=input()

  for  i in range(c):

    bs=input()

    h=raw_input()

    t=input()

    p.append(Payslip(bs,h,t))

  pa=Pd()

  pf=pa.getpf(p)

  print pf



EXPLANATION FOR ABOVE PROGRAM


This Python program contains two classes: Payslip and Pd (short for "Pay Slip Demo"). It also contains a main block of code that creates instances of these classes and calls their methods.


The Payslip class has three attributes: bs, h, and t, which represent the employee's basic salary, HRA (house rent allowance), and ITA (income tax allowance). The constructor __init__() takes these attributes as input parameters and assigns them to instance variables of the same name.


The Pd class contains a method getpf() that takes a list of Payslip objects as input and returns the highest PF (provident fund) amount among the objects. PF is calculated as 12% of the employee's basic salary. The method first initializes an empty list k, then iterates over the input list and calculates the PF for each Payslip object by multiplying the basic salary with 0.12 (i.e., 12%). The calculated PF amounts are appended to the list k. Finally, the method finds the maximum value in the list k and returns it as an integer.


In the main block of code, the program first creates an empty list p and takes an integer input c from the user. This input represents the number of Payslip objects that will be created. Then, in a for loop, the program takes three input values from the user (basic salary, HRA, and ITA) and uses them to create a new Payslip object. The object is added to the list p. After the loop, the program creates an instance of the Pd class and calls its getpf() method with the p list as input. The returned value (highest PF amount) is stored in the variable pf, which is printed to the console.


Comments