0 like 0 dislike
2,091 views
Python code below :
in Service-based-companies by Expert (17,730 points) | 2,091 views

1 Answer

0 like 0 dislike
class Citizen:
  def __init__(self,citizenid,citizenname,citizenage,isfrontlineworker,vaccineoptedfor):
    self.id=citizenid
    self.name=citizenname
    self.age=citizenage
    self.workertype=isfrontlineworker
    self.vaccine=vaccineoptedfor
  def setpreference(l):
    return 1 if l.workertype.lower()=="yes" or l.age>45 else 0
class vaccinationDrive:
  def __init__(self,citizen):
    self.clist=citizen
  def getpreferredvaccinationcount(self):
    count=0
    for i in self.clist:
     if Citizen.setpreference(i):
       count+=1
    return count if count else "preferred citizen not found"
  def getcitizensaspervaccine(self,vaccinename):
    l=[]
    for i in self.clist:
      if i.vaccine==vaccinename:
        l.append(i)
    if l:
      l=sorted(l,key=lambda l:l.age)
    return l if l else "Citizen not found"
if __name__=='__main__':
  mylist=[]
  n=int(input())
  for i in range(n):
    id=int(input())
    name=input()
    age=int(input())
    workerstype=input()
    vaccine=input()
    mylist.append(Citizen(id,name,age,workerstype,vaccine))
  name=input()
  obj=vaccinationDrive(mylist)
  ans=obj.getcitizensaspervaccine(name)
  print(ans) if "not" in ans else [print(str(i.id)+'\n'+i.name+'\n'+str(i.age)) for i in ans]
  print(obj.getpreferredvaccinationcount(),end="")
by Expert (17,730 points)

Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .