0% found this document useful (0 votes)
387 views2 pages

Mock SBQ 2 Solution

The document defines two classes - Book and BookStore. The Book class defines attributes for a book like pages, price etc. The BookStore class initializes a book store with a name and list of books, and defines methods to find the book with the minimum ID and sort the book list by ID. It then takes user input to create a list of Book objects, initializes a BookStore with the list and calls the BookStore methods to output the book with minimum ID details and sorted list of IDs.

Uploaded by

Technical Akash
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
0% found this document useful (0 votes)
387 views2 pages

Mock SBQ 2 Solution

The document defines two classes - Book and BookStore. The Book class defines attributes for a book like pages, price etc. The BookStore class initializes a book store with a name and list of books, and defines methods to find the book with the minimum ID and sort the book list by ID. It then takes user input to create a list of Book objects, initializes a BookStore with the list and calls the BookStore methods to output the book with minimum ID details and sorted list of IDs.

Uploaded by

Technical Akash
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

Python SBQ

------------------------

class Book:
def __init__(self,pages,price,author,bookId,title):
self.pages = pages
self.price = price
self.author = author
self.bookId = bookId
self.title = title
class BookStore:
def __init__(self,bookStoreName,bookList):
self.bookStoreName = bookStoreName
self.bookList = bookList
def findMinimumBookID(self):
min_obj = min(self.bookList, key=lambda x:x.bookId)
return min_obj
def sortbookById(self):
ans1 = sorted(self.bookList, key=lambda x:x.bookId)
ans2 = []
for i in ans1:
ans2.append(i.bookId)
if len(ans2)==0:
return None
else:
return ans2

count = int(input())
bookList = []
for i in range(count):
pages = int(input())
price = int(input())
author = input()
bookId = int(input())
title = input()
b = Book(pages,price,author,bookId,title)
bookList.append(b)
bs = BookStore("ABC",bookList)
x = bs.findMinimumBookID()
y = bs.sortbookById()
print(x.pages)
print(x.price)
print(x.author)
print(x.bookId)
print(x.title)
for i in range(len(y)):
print(y[i])
Unix SBQ
--------------------------

awk 'BEGIN{FS=",";IGNORECASE=1}
{
if($3=="Finance" || $3=="finance" ||$3=="FINANCE")
{
sum=$4+sum
count=count+1
}
}END{
if(count>0)
{
print("Total Asset Price = "sum)
}
else
{
print("No Asset Found")
}
}'

You might also like