Skip to content

Instantly share code, notes, and snippets.

@zakgrin
Created October 12, 2018 13:26
Show Gist options
  • Save zakgrin/86178549e81cf0a8a4c4bbe37bc9995e to your computer and use it in GitHub Desktop.
Save zakgrin/86178549e81cf0a8a4c4bbe37bc9995e to your computer and use it in GitHub Desktop.
class Authors:
def __init__(self, author1, author2):
self.author1=author1
self.author2=author2
def __str__(self):
return self.author1 + ' and ' + self.author2
class Book:
def __init__(self, book_name, ISBN , pages_number):
self.book_name=book_name
self.ISBN=ISBN
self.pages_number=pages_number
#self.authors=[]
#self.authors.append(Authors)
def add_author(self, author1, author2):
#self.authers.append(Authors(author1,author2))
self.authors=[]
self.authors.append((author1,author2))
def __str__(self):
res = "Book Name: " + self.book_name
#res = res + "\nAuthor Name: " + self.auther_name
res = res + "\nISBN_10: " + self.ISBN
res = res + "\nNumber of Pages: " + str(self.pages_number)
res = res + "\nAuthors: "
for n in self.authors:
res = res + "\n" + str(n)
#res = res + "\n" + str(n)
return res
def __gt__(self, other):
return self.pages_number>other.pages_number
def __eq__(self,other):
return self.pages_number==other.pages_number
def __le__(self, other):
return self.pages_number<=other.pages_number
def __ge__(self, other):
return self.pages_number>=other.pages_number
import Books
#import Merge_Sor_Box
B=[]
book_list=[]
B.append(Books.Book('Fluent Forever','0385348118',336))
B[-1].add_author('Gabriel Wyner','')
B.append(Books.Book('Amazing Memory','9781907486975',208))
B[-1].add_author('Dominic OBrien','')
B.append(Books.Book('How to Read a Book','0671212095',426))
B[-1].add_author('Mortimer J. Adler','Charles Van Doren')
print('Unsorted books list:')
for i in range (len(B)):
print(B[i].book_name,B[i].pages_number)
B.sort()
print('\nSorted books list:')
for i in range (len(B)):
print(B[i].book_name,B[i].pages_number)
@zakgrin
Copy link
Author

zakgrin commented Oct 12, 2018

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment