100% found this document useful (1 vote)
90 views

Mock Pra 3 Solution Python

This document defines two classes - Image and Album. The Image class represents images with attributes like ID, name, coordinates and type. The Album class represents an album containing a list of images. It has a method to calculate and return filtered images of a given type from the album after applying a filter percentage to their coordinates. The code at the end tests this functionality by creating sample Image objects, adding them to an Album, and calling the Album method to filter and return matching images.

Uploaded by

Siva Karthick
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
90 views

Mock Pra 3 Solution Python

This document defines two classes - Image and Album. The Image class represents images with attributes like ID, name, coordinates and type. The Album class represents an album containing a list of images. It has a method to calculate and return filtered images of a given type from the album after applying a filter percentage to their coordinates. The code at the end tests this functionality by creating sample Image objects, adding them to an Album, and calling the Album method to filter and return matching images.

Uploaded by

Siva Karthick
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

class Image:

def __init__(self,image_id,image_name,x_coordinates,y_coordinates,image_type):
self.image_id = image_id
self.image_name = image_name
self.x_coordinates = x_coordinates
self.y_coordinates = y_coordinates
self.image_type = image_type

def apply_filter(self,number):
self.x_coordinates = self.x_coordinates + self.x_coordinates*(number/100)
self.y_coordinates = self.y_coordinates + self.y_coordinates*(number/100)

class Album:
def __init__(self,album_name,img_list):
self.album_name = album_name
self.img_list = img_list

def calculate_coordinates(self,fpercent,imgtype):
l=[]
for i in self.img_list:
if i.image_type.lower() == imgtype.lower():
if fpercent > 0:
i.apply_filter(fpercent)
l.append(i)
if len(l) == 0:
return None
else:
l.sort(key = lambda x:x.image_name)
return l

if __name__ == "__main__":
n = int(input())
l1=[]
for i in range(n):
iid = int(input())
iname = input()
xcoord = int(input())
ycoord = int(input())
itype = input()
f = Image(iid,iname,xcoord,ycoord,itype)
l1.append(f)

itype = input()
fpercent = int(input())
a = Album("Wedding",l1)
c = a.calculate_coordinates(fpercent,itype)
if c == None:
print("Image Not Found.")
else:
for i in c:
print(i.image_name,i.x_coordinates,i.y_coordinates)

You might also like