​

Question 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

Solution:

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

Question 2

Create a class Stock having attributes StockName,StockSector,StockValue.

Create a method getStockList with takes a list of Stock objects and a StockSector(string) and returns a list containing stocks of the given sector having value more than 500.

input:

3

TCS

IT

1000

INFY

IT

400

BMW

Auto

1200

IT

Output:

TCS

Solution:

class Stock:
def __init__(self,sn,ss,sv):
self.sn=sn
self.ss=ss
self.sv=sv
class StockDemo:
def __init__(self):
self.a=10
def gets(self,l,s):
k=[]
for i in l:
if(i.ss==s and i.sv>500):
k.append(i)
return k

if __name__=='__main__':
c=input()
p=[]
for i in range(c):
sn=raw_input()
ss=raw_input()
sv=input()
o=Stock(sn,ss,sv)
p.append(o)
s=raw_input()
pra=StockDemo()
l=pra.gets(p,s)
for i in l:
print i.sn,i.sv