V5-Module 2 Python OOPS Assignment

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

class Employee:

def __init__(self):
self.emp_id = None
self.gender = None
self.salary = None
self.performance_rating = None

def get_details(self):
self.emp_id = int(input("Enter Employee ID:
"))
self.gender = input("Enter Gender (M/F): ")
self.salary = int(input("Enter Salary: "))
self.performance_rating = int(input("Enter
Performance Rating (1-5): "))

def display_details(self):
print(f'Employee ID: {self.emp_id}')
print(f'Gender: {self.gender}')
print(f'Salary: {self.salary}')
print(f'Performance Rating:
{self.performance_rating}')
class JoiningDetail:
def __init__(self):
self.date_of_joining = None

def get_doj(self):
self.date_of_joining = input("Enter Date of
Joining (DD-MM-YYYY): ")

def display_doj(self):
print(f'Date of Joining:
{self.date_of_joining}')

class Information(Employee, JoiningDetail):


def __init__(self):
Employee.__init__(self)
JoiningDetail.__init__(self)

def get_all_details(self):
self.get_details()
self.get_doj()
print("_______________________")

def display_all_details(self):
self.display_details()
self.display_doj()
print("_______________________")
def enter_information(self):
employee_list = []
n = int(input("Number of employees you want
to add: "))
for i in range(n):
emp_info = Information()
emp_info.get_all_details()
employee_list.append(emp_info)
return employee_list

def display_information(self, employee_list):


for emp in employee_list:
emp.display_all_details()

def sort_by_rating(self,employee_list):

sorted_by_rating=sorted(employee_list,reverse=
True, key= lambda i: i.performance_rating)

return sorted_by_rating[:3]

def sort_by_doj(self,employee_list):
sorted_by_doj= sorted(employee_list,
reverse=False, key= lambda employee:
employee.date_of_joining)

return sorted_by_doj
obj=Information()

print('Enter information1\n')
employee_ls=obj.enter_information()

print('-----------------------\n\n')

print('display all the information of employees\n')


obj.display_information(employee_ls)

print('-----------------------\n\n')

print('sorted by rating\n')
sorted_employee_ls=obj.sort_by_rating(employee_ls)
obj.display_information(sorted_employee_ls)

print('-----------------------\n\n')

print('sorted by doj \n')


sorted_employee_ls=obj.sort_by_doj(sorted_employee_
ls)
obj.display_information(sorted_employee_ls)
class vehicle:
def __init__(self, fare_of_vehicle = None):
self.fare_of_vehicle = fare_of_vehicle

def get_fare(self,name):
self.fare_of_vehicle= float(input(f"fare of
{name}: "))
return self.fare_of_vehicle

bus=vehicle()
bus_fare= bus.get_fare("Bus")
car=vehicle()
car_fare= car.get_fare("Car")
train=vehicle()
train_fare= train.get_fare("Train")
truck=vehicle()
truck_fare= truck.get_fare("Truck")
ship= vehicle()
ship_fare= ship.get_fare("Ship")

total_fare=bus_fare+
car_fare+train_fare+truck_fare+ship_fare
print(f"Total fare is: {total_fare}")
match= {
'test1':{'Dhoni':56, 'Balaji':94},
'test2':{'Balaji':80, 'Dravid':105}
}

def max_score(match):

max_score= 0
top_player=''

for test,player in match.items():


for player, score in player.items():

if max_score<score:
max_score=score
top_player=player

return top_player, max_score

print(max_score(match))

import random

cards=[1,2,3,4,5,6,7,8]
score=0
option=''
num1=0
prediction=''

print("Welcome to the game\n")


print("Enter any option given below:\n")
option=input("a.Start \nb.You can write 'Stop'
anytime to stop the game: \n\n").lower()

def card_game():
global score
num1= random.choice(cards)
print(f"\nRandomly selected number: {num1}\n")
prediction= input("The next number will be lower
or higher: ").lower()
while prediction!="stop":
num2= random.choice(cards)
print(f"\nRandomly selected number: {num2}\n")
if (prediction=="lower"):
if(num1>num2):
print("Great! You are correct\n")
score+=20
print(f"Current score is: {score}\n")
else:
print("Oh no, you are wrong. No worries
better luck next time\n")
if score>0:
score-=15
else: score=0
print(f"Current score is: {score}\n")

elif(prediction=="higher"):
if(num1<num2):
print("Great! You are correct\n")
score+=20
print(f"Current score is: {score}\n")
else:

print("Oh no, you are wrong. No worries


better luck next time\n")
if score>0:
score-=15
else: score=0
print(f"Current score is: {score}\n")

else: print("invalid input\n")

print(f'\nRight now number is: {num2}')


prediction=input("The next number will be lower
or higher: ").lower()
num1=num2

print(f"\nYour total score is: {score}")


print("\nThank you for playing this game\nHave a
great time ahead")

if option=="start":
card_game()
elif option=="stop":
print("\nSee you next time")
quit()
else:
print("invalid input\n")
option=input("a.Start \nb.You can write 'Stop'
anytime to stop the game \n\n").lower()
card_game()

car_0={}

car_0={'x_pos':10, 'y_pos':72, 'speed':'medium'}

print(f'Original dictionary: {car_0}')

if car_0['speed']=='slow':
car_0['x_pos']+=2
elif car_0['speed']=='medium':
car_0['x_pos']+=9
else:
car_0['x_pos']+=22
print(f'\nModified Dictionary: {car_0}')

from abc import ABC, abstractmethod

class office(ABC):
@abstractmethod
def check_id(self):
pass

class entry_gate(office):

def check_id(self):
print("Shown ID and entered office")

class parking_space(office):

def check_id(self):
print("Shown ID and entered parking space")
class office_canteen(office):

def check_id(self):
print("Shown ID and entered canteen")

enter=entry_gate()
enter.check_id()
parking=parking_space()
parking.check_id()
canteen=office_canteen()
canteen.check_id()

class vehicles:
def __init__(self, pemail_id, pname,page,
pnumber):
self._p_email_id= pemail_id
self.p_name= pname
self.p_age=page
self.__p_number=pnumber

def get_p_email_id(self):
return self._p_email_id

def get_p_number(self):
return self.__p_number

class car:
def __init__(self,data):
self.p_data=data

def move(self):
print("A car is moving ")
print(f'First 4 letters of email_id:
{self.p_data.get_p_email_id()[:2]}')
print(f'First two numbers of mobile number:
{int(str(self.p_data.get_p_number())[-2:])}')

class aeroplane:
def __init__(self,data):
self.p_data=data

def move(self):
print("An aeroplane is moving")
print(f'First 4 letters of email_id:
{self.p_data.get_p_email_id()[:2]}')
print(f'First two numbers of mobile number:
{int(str(self.p_data.get_p_number())[-2:])}')

class cruise:
def __init__(self,data):
self.p_data=data
def move(self,data):
print("A Ship is moving")
print(f'First 4 letters of email_id:
{self.p_data.get_p_email_id()[:2]}')
print(f'First two numbers of mobile number:
{int(str(self.p_data.get_p_number())[-2:])}')

passenger1= vehicles('abcdef@gmail.com', 'Abc def',


'30', 1234567890)

passenger_in_car= car(passenger1)
passenger_in_car.move()
print('-----------------------\n\n')
passenger_on_aeroplane= aeroplane(passenger1)
passenger_on_aeroplane.move()
print('-----------------------\n\n')
passenger_on_cruise= cruise(passenger1)
passenger_on_cruise.move()

numbers = list(range(51))

def even_num(num):
if num%2 ==0:
return num

def odd_num(num):
if num%2!=0:
return num

def square(num):
return num**2

even_numbers = list(filter(even_num, numbers))


squared_even_numbers=
list(map(square,even_numbers))
print(f'even numbers and their square are: \n
{list(zip(even_numbers,squared_even_numbers))}\n')

odd_numbers= list(filter(odd_num,numbers))
squared_odd_numbers= list(map(square,odd_numbers))
print(f' odd numbers and their square are:\n
{list(zip(odd_numbers, squared_odd_numbers))}')

class triangle:
def __init__(self,angle1,angle2,angle3):
self.t_angle1= angle1
self.t_angle2= angle2
self.t_angle3= angle3

class sides:

def __init__(self, number_of_sides):


self.s_number_of_sides= 3

class triangle:
def __init__(self, angle1, angle2, angle3):
self.a_angle1= angle1
self.a_angle2= angle2
self.a_angle3= angle3

def check_angles(self):
if self.a_angle1 + self.a_angle2 +
self.a_angle3==180:
print("It's a triangle")
return True
else:
print("It's not a triangle")
return False

obj=triangle(70,80,40)

obj.check_angles()

class triangle:
def __init__(self, angle1, angle2, angle3):
self.angle1= angle1
self.angle2= angle2
self.angle3= angle3

def check_angles(self):
return self.angle1 + self.angle2 +
self.angle3==180

def check_triangle(self):

if not self.check_angles():
print("It's not a triangle\n\n")
angles_of_triangle= [self.angle1, self.angle2,
self.angle3]

if any(i>90 for i in angles_of_triangle):


print("It is an obtuse triangle\n\n")

elif all(i<90 for i in angles_of_triangle):


print("It is an acute triangle\n\n")

class isosceles_triangle(triangle):
def __init__(self,angle1, angle2, angle3):
super().__init__(angle1, angle2, angle3)

def check_triangle(self):
if self.angle1 == self.angle2 or self.angle2 ==
self.angle3 or self.angle3 == self.angle1:
print("It's an isosceles triangle\n\n")
else:
print("It's not an isosceles
triangle\n\n")

class right_triangle(triangle):
def __init__(self,angle1, angle2, angle3):
super().__init__(angle1, angle2, angle3)

def check_triangle(self):
if any(i==90 for i in [self.angle1, self.angle2,
self.angle3]):
print("It's a right triangle\n\n")
else:
print("It's not a right triangle\n\n")

class equilateral_triangle(triangle):
def __init__(self,angle1, angle2, angle3):
super().__init__(angle1, angle2, angle3)

def check_triangle(self):
if self.angle1==self.angle2 and
self.angle2==self.angle3:
print("It's an equilateral triangle\n\n")
else:
print("It's not an equilateral triangle\n\n")

#Answer- 11.1
obj= triangle(40,30,110)
obj.check_triangle()

#Answer- 11.2
obj.check_angles()
obj.check_triangle()

#Answer- 11.4
obj_isoceles_triangle= isosceles_triangle(45,45,90)
obj_isoceles_triangle.check_triangle()

obj_right_triangle= right_triangle(90, 60, 30)


obj_right_triangle.check_triangle()
obj_equilateral_triangle=
equilateral_triangle(60,60,60)
obj_equilateral_triangle.check_triangle()

class right_triangle:
def __init__(self, angle1, angle2, angle3):
self.angle1 = angle1
self.angle2 = angle2
self.angle3 = angle3

def check_right_triangle(self):
if any(i == 90 for i in [self.angle1,
self.angle2, self.angle3]):
print("It's a right triangle\n\n")
else:
print("It's not a right triangle\n\n")

class isosceles_triangle:
def __init__(self, angle1, angle2, angle3):
self.angle1 = angle1
self.angle2 = angle2
self.angle3 = angle3

def check_isosceles_triangle(self):
if self.angle1 == self.angle2 or self.angle2
== self.angle3 or self.angle3 == self.angle1:
print("It's an isosceles triangle\n\n")
else:
print("It's not an isosceles
triangle\n\n")

class isosceles_right_triangle(right_triangle,
isosceles_triangle):
def __init__(self, angle1, angle2, angle3):

super().__init__(angle1, angle2, angle3)

def check_triangle(self):
self.check_right_triangle()
self.check_isosceles_triangle()

obj= isosceles_right_triangle(90,60,30)
obj.check_triangle()

You might also like