PA Programming Solution - 2 March 2020
Q1. GIVEN some strings in that we need to print the strings which doesn't contain vowels in it..
Input 1:
4
avoid
ball
ntng
nani
Output 1:
ntng
Input 2:
3
avoid
ball
cat
Output 2:
no values
Solution:
n=int(input())
l=[]
vow=['a','e','i','o','u']
for i in range(n):
l.append(input())
pre=[]
for j in range(n):
for i in range(len(l[i])):
if(l[i][j] in vow):
pre.append(l[i])
pre=list(set(pre))
if(len(pre)==len(l)):
print("no values")
else:
for i in range(n):
if(l[i] in pre):
pass
else:
print(l[i])
Q2. Given passenger ID name gender distance
In last two lines they provide the passenger ID and discount percentage
We need to print the discount to be given for that particular passenger if that given Id is not in the list print no name or no value
Input :
4
101
a
f
10000
102
b
m
12000
103
c
f
45000
104
d
m
65000
101
5
Solution:
class Passenger:
def __init__(self,pid,pname,pgender,pmiles):
self.pid=pid
self.pname=pname
self.pgender=pgender
self.pmiles=pmiles
def calculate_discount(self,pid,discount_rate):
for i in pass_list:
if i.pid==pid:
discount=(i.pmiles*discount_rate)/100
return discount
class Organisation(Passenger):
def __init__(self,oname,pass_list):
self.oname=oname
self.pass_list=pass_list
if __name__ == '__main__':
n=int(input())
pass_list=[]
for i in range(n):
pid=input()
pname=input()
pgender=input()
pmiles=int(input())
pass_list.append(Passenger(pid,pname,pgender,pmiles))
pid=input()
discount_rate=int(input())
o=Organisation('TCS',pass_list)
discount=o.calculate_discount(pid,discount_rate)
if discount<0:
print("Passenger not eligible for discount")
else:
print("The discount of passenger "+pid+" is " +str(discount))
# cook your dish here
ReplyDeleteclass Passenger:
def __init__(self,p_id,p_name,p_gender,p_dist):
self.p_id = p_id
self.p_name = p_name
self.p_gender = p_gender
self.p_dist = p_dist
class Organisation:
def __init__(self,org_name,p_list):
self.org_name = org_name
self.p_list = p_list
def cal_disc(self,p_id_inp,discount_percentage):
for i in self.p_list:
if(i.p_id == p_id_inp):
discount = (i.p_dist*discount_percentage)/100
return discount
if __name__ == '__main__':
count = int(input())
p_list = []
for i in range(count):
p_id = int(input())
p_name = input()
p_gender = input()
p_dist = int(input())
p_list.append(Passenger(p_id,p_name,p_gender,p_dist))
o = Organisation("ABC",p_list)
p_id_inp = int(input())
discount_percentage = int(input())
print("Total discount : ",o.cal_disc(p_id_inp,discount_percentage))