PA Programming Solution - 17th December 2019
Q1. 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.
Sample Input:
2
10000
2000
1000
50000
3000
2000
Sample Output:
6000
Solution :
class paySlip:
def __init__(self,basicSalary,hra,ita):
self.basicSalary = basicSalary
self.hra = hra
self.ita = ita
class paySlipDemo:
def __init__(self):
maxp = 0
def getHighestPF(self,paylist):
pfList = []
for i in paylist:
maxp = i.basicSalary * 0.12
pfList.append(maxp)
maxpf = max(pfList)
return print(maxpf)
if __name__ == '__main__':
count = int(input())
paylist = []
for i in range(count):
basicSalary = int(input())
hra = int(input())
ita = int(input())
paylist.append(paySlip(basicSalary,hra,ita))
paySlip = paySlipDemo().getHighestPF(paylist)
Output:
2
10000
2000
1000
50000
3000
2000
6000.0
Q2.Create a class Stock having attributes StockName,StockSector,StockValue.Create a class StockDemo having 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.
Sample Input:
3
TCS
IT
1000
INFY
IT
400
BMW
Auto
1200
IT
Sample Output:
TCS
Solution :
class Stock:
def __init__(self,StockName,StockSector,StockValue):
self.StockName = StockName
self.StockSector = StockSector
self.StockValue = StockValue
class StockDemo:
def getStockList(self,Stocks,StockSector):
StockList = []
for i in Stocks:
if i.StockSector == StockSector and i.StockValue > 500:
StockList.append(i.StockName)
return StockList
if __name__=='__main__':
count = int(input())
Stocks = []
for i in range(count):
StockName = input()
StockSector = input()
StockValue = int(input())
Stocks.append(Stock(StockName,StockSector,StockValue))
StockSector1 = input()
output = StockDemo().getStockList(Stocks,StockSector1)
for j in output:
print(j)
Output:
3
TCS
IT
1000
INFY
IT
400
BMW
AUTO
1200
IT
TCS
Comments
Post a Comment