PA Programming Solution - 10 February 2020

PA Programming Solution - 10 February 2020

 

Q1. Create a function palindrome_list() that takes a list of strings as an argument. returns the list of strings which are only strings

Input:
3
Malayalam
Radar
Bhushan


Output:
Malayalam
Radar
Solution:


def palindrome_list(l):
       res=[]
       for i in l:
             j=i.lower()
             if(j==j[::-1]):
                    res.append(i)
       return res


if  __name__ == '__main__':
       count=int(input())
       input_list=[]
       for i in range(count):
             input_list.append(input())
       result=palindrome_list(input_list)
       for i in result:
             print(i)



Q2. Create a class employee with attributes
  emp Id,
  emp name,
  emp role,
  emp salary
In the same class,define method increment_salary() which takes number as an argument, here number represents the percentage by which the salary should be incremented.
Create another class organization with attributes org_name and list of employee objects
In the same class create a method calculate_salary() which takes string and number as the input arguments.string input represents the employee role and number represents the percentage by which the salary should be incremented,return list of employee objects whose salary has incremented.
Note: use increment_salary method in this method


Input:
4
100
rajesh
developer
40000
101
ayesha
developer
41000
102
hari
analyst
45000
103
amar
manager
60000
developer
5


Output:
rajesh
42000.0
ayesha
43050.0


Solution:

class Employee:
    def __init__(self,id,name,role,salary):
        self.emp_id=id
        self.emp_name=name
        self.emp_role=role
        self.emp_salary=salary

    def increse_salary(self,no):
        self.emp_salary+=self.emp_salary*(no/100)



class Organisation:
    def __init__(self,oname,elist):
        self.org_name=name
        self.emp_list=elist

    def calculate_salary(self,role,percentage):
        result=[]
        for i in self.emp_list:
            if(i.emp_role==role):
                i.increse_salary(percetage)
                result.append(i)
        return result

if  __name__ == '__main__':
    count=int(input())
    emp_l=[]
    for i in range(count):
        id=int(input())
        name=input()
        role=input()
        salary=int(input())
        emp_l.append(Employee(id,name,role,salary))
    o=Organisation("XYZ",emp_l)
    role=input()
    percentage=int(input())
    result=o.calculate_salary(role,percentage)
    for i in result:
        print(i.emp_name)
        print(i.emp_salary)




Comments