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 getHighestPF(self,paylist):
pflist=[]
for i in paylist:
pf=0.12*basicSalary
pflist.append(pf)
print(max(pflist))
if __name__=='__main__':
count=int(input("Enter the number of times you want to input payslip data\n"))
paylist=[]
for i in range (count):
basicSalary=int(input("Enter basic salary\n"))
hra = int(input("Enter hra\n"))
ita= int(input("Enter ita\n"))
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,olist,StockSector):
stockList=[]
for i in olist:
if i.StockValue>500:
stockList.append(i.StockName)
return (stockList)
if __name__=='__main__':
count=int(input("Enter how many stocks you want to enter\n"))
olist=[]
for i in range (count):
StockName=input("enetr stock name\n")
StockSector=input("enter stock sector\n")
StockValue=int(input("enter stock value\n"))
olist.append(Stock(StockName,StockSector,StockValue))
StockSector1=input("enter the stock sector for more specification")
output=StockDemo().getStockList(olist,StockSector1)
for j in output:
print(j)
Output:
3
TCS
IT
1000
INFY
IT
400
BMW
AUTO
1200
IT
TCS
theinfinitevisions
Thursday, August 13, 2020
Related Posts