PA Programming Solution - 28th December 2019
Q1.Create a class called apartment with attributes flat-number, owner name, electicitybillamount. Create another class apartment_demo with def init(self): pass to create a method getSecondMinBill that takes the list of objects and gives the second minimum electricity bill as output.
Sample Input:
3
1000
Hari
5000
1001
Hena
5002
1002
Harsha
5001
Sample Output:
5001
Solution:
class apartment:
def __init__(self,flatNumber,ownerName,eBillAmt):
self.flatNumber = flatNumber
self.ownerName = ownerName
self.eBillAmt = eBillAmt
class apartment_demo:
def __init__(self):
pass
def getSecondMinBill(self,billList):
bills = []
for i in billList:
bills.append(i.eBillAmt)
bills.sort()
second = bills[1]
return print(second)
if __name__=='__main__':
count = int(input())
billList = []
for i in range(count):
flatNumber = int(input())
ownerName = input()
eBillAmt = int(input())
billList.append(apartment(flatNumber,ownerName,eBillAmt))
output = apartment_demo().getSecondMinBill(billList)
Q2. Create a class Bill with attributes mobile number and payment bill. Create another class mobile with attributes serviceprovider, mobilenumber, dataused, payment method. Service provider may be airtel or jio.Data used is integer values in Gigabytes(GB). Payment method may be paytm, gpay, amazon and soon. Create a method calculatebill that takes the list of objects and calculates the bill and returns the list of objects of class bill with mobile number and paymentbill.
The payment is calculated as follows:
1. If the service provider is airtel, the bill is Rs.11 for every 1GB used and if it is jio, the bill is Rs.10 for every 1GB used.
2.If the payment method is paytm there is a cash back of 10% of the total bill for airtel users only.The bill is calculated and rounded off after deducing the cashback value.
Sample Input:
3
airtel
123
16
paytm
airtel
456
10
amazon
jio
789
10
paytm
Sample Output:
(123,158)
(456,110)
(789,100)
Solution:
class Bill:
def __init__(self,mobNumber,payBill):
self.mobNumber = mobNumber
self.payBill = payBill
class Mobile:
def __init__(self,serviceProvider,mobNumber,dataUsed,payMethod):
self.serviceProvider = serviceProvider
self.mobNumber = mobNumber
self.dataUsed = dataUsed
self.payMethod = payMethod
def calculateBill(self,billList):
bills = []
for i in billList:
if i.serviceProvider == "airtel":
billamt = i.dataUsed * 11
if i.payMethod == "paytm":
totalbill = billamt - (billamt * 0.1)
elif i.serviceProvider == 'jio':
billamt = i.dataUsed * 10
totalbill = billamt
bills.append(Bill(i.mobNumber,int(totalbill)))
return bills
if __name__=='__main__':
count = int(input())
bills = []
for i in range(count):
serviceProvider = input()
mobNumber = int(input())
dataUsed = int(input())
payMethod = input()
bills.append(Mobile(serviceProvider,mobNumber,dataUsed,payMethod))
output = Mobile("",0,0,"").calculateBill(bills)
for j in output:
print("(",j.mobNumber,",",j.payBill,")")
class Bill:
ReplyDeletedef __init__(self,MobileNumber,PaymentBill):
self.MobileNumber = MobileNumber
self.PaymentBill = PaymentBill
class Mobile:
def __init__(self,ServiceProvider,MobileNumber,DataUsed,PaymentMethod):
self.ServiceProvider = ServiceProvider
self.MobileNumber = MobileNumber
self.DataUsed = DataUsed
self.PaymentMethod = PaymentMethod
def CalculateBill(self,infos):
bills = []
for k in info:
if k.ServiceProvider == "airtel":
bill = k.DataUsed * 11
totalbill = bill
if k.PaymentMethod == "paytm":
totalbill = bill - (bill*0.1)
elif k.ServiceProvider == "jio":
bill = k.DataUsed * 10
totalbill = bill
bills.append(Bill(k.MobileNumber,int(totalbill)))
return bills
if __name__ == '__main__':
count = int(input())
info = []
for i in range(count):
ServiceProvider = input()
MobileNumber = int(input())
DataUsed = int(input())
PaymentMethod = input()
info.append(Mobile(ServiceProvider,MobileNumber,DataUsed,PaymentMethod))
output = Mobile('',0,0,'').CalculateBill(info)
for j in output:
print(j.MobileNumber,'',j.PaymentBill)
Corrected Program
Deleteclass Bill:
ReplyDeletedef __init__(self,mob_num,pay_bill):
self.mob_num=mob_num
self.pay_bill=pay_bill
class Mobile:
def __init__(self,serviceprovider,mob_num,dataused,pay_method):
self.serviceprovider=serviceprovider
self.mob_num=mob_num
self.dataused=dataused
self.pay_method=pay_method
def calculateBill(self,billList):
bills=[]
for i in billList:
if i.serviceprovider=="airtel":
billamt=i.dataused*11
totalbill=billamt
if i.pay_method=="paytm":
totalbill=billamt-(billamt*0.1)
elif i.serviceprovider=="jio":
billamt=i.dataused*10
totalbill=billamt
bills.append(Bill(i.mob_num,int(totalbill)))
return bills
if __name__=="__main__":
count=int(input())
bills=[]
for i in range(count):
serviceprovider=input()
mob_num=int(input())
dataused=int(input())
pay_method=input()
bills.append(Mobile(serviceprovider,mob_num,dataused,pay_method))
output=Mobile("",0,0,"").calculateBill(bills)
for j in output:
print("(",j.mob_num,",",j.pay_bill,")")