Q1. Write a python program to find the repeated items of a tuple.
t = (2,34,45,6,7,4,5,6,78,34,2)
print(t)
l=[]
print("\nRepeated Elements are\n")
for i in t:
if t.count(i)>1:
if i not in l:
l.append(i)
print(l)(2, 34, 45, 6, 7, 4, 5, 6, 78, 34, 2)
Repeated Elements are
[2, 34, 6]
Q2. Write a python program with user defined function which accept long string containing multiple words and it return same string with the words in backwards order.
Example: Input= “I am Msc student” then output = ”student Msc am I”
def reverse_string_words(text):
for line in text.split('\n'):
return(' '.join(line.split()[::-1]))
print(reverse_string_words("I am MSc Student"))
print(reverse_string_words("How Are You"))Student MSc am I
You Are How
Q2. Define a class Employee having members – id, name, department, salary. Create a subclass called ―Manager with member bonus. Define methods accept and display in both the classes. Create n objects of the Manager class and display the details of the manager having the maximum total salary (salary + bonus).
class Employee:
def AcceptEmp(self):
self.Id=int(input("Enter emp id:"))
self.Name=input("Enter emp name:")
self.Dept=input("Enter emp Dept:")
self.Sal=int(input("Enter emp Salary:"))
def DisplayEmp(self):
print("Emp id:",self.Id)
print("Emp Name:",self.Name)
print("Emp Dept:",self.Dept)
print("Emp Salary:",self.Sal)
class Manager(Employee):
def AcceptMgr(self):
self.bonus=int(input("Enter Manager Bonus"))
def DisplayMgr(self):
print("Manger Bonus is:",self.bonus)
self.TotalSal=self.Sal+self.bonus
print("Total Salary: ", self.TotalSal)
n=int(input("Enter How may Managers:"))
s=[]
for i in range(0,n):
x=input("Enter Object Name:")
s.append(x)
print(s)
for j in range(0,n):
s[j]=Manager()
s[j].AcceptEmp()
s[j].AcceptMgr()
for k in range(0,n):
print("\nDisplay Details of Manager",k+1)
s[k].DisplayEmp()
s[k].DisplayMgr()
maxTotalSal= s[0].TotalSal
maxIndex=0
for j in range(1,n):
if s[j].TotalSal > maxTotalSal:
maxTotalSal= s[j].TotalSal
maxIndex=j
print("\nMaximum Salary(Salary+Bonus)")
s[maxIndex].DisplayEmp()
s[maxIndex].DisplayMgr()Enter How may Managers:3
Enter Object Name:e1
['e1']
Enter Object Name:e2
['e1', 'e2']
Enter Object Name:e3
['e1', 'e2', 'e3']
Enter emp id:100
Enter emp name:SACHIN
Enter emp Dept:COMP
Enter emp Salary:85000
Enter Manager Bonus7000
Enter emp id:102
Enter emp name:RAHUL
Enter emp Dept:IT
Enter emp Salary:65000
Enter Manager Bonus10000
Enter emp id:103
Enter emp name:SAGAR
Enter emp Dept:ACCOUNT
Enter emp Salary:45000
Enter Manager Bonus4500
Display Details of Manager 1
Emp id: 100
Emp Name: SACHIN
Emp Dept: COMP
Emp Salary: 85000
Manger Bonus is: 7000
Total Salary: 92000
Display Details of Manager 2
Emp id: 102
Emp Name: RAHUL
Emp Dept: IT
Emp Salary: 65000
Manger Bonus is: 10000
Total Salary: 75000
Display Details of Manager 3
Emp id: 103
Emp Name: SAGAR
Emp Dept: ACCOUNT
Emp Salary: 45000
Manger Bonus is: 4500
Total Salary: 49500
0 Comments:
Post a Comment