Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Create the class separately, and get the input separately. Also, you want to mention that each variable is an instance variable, not in the local scope:</p> <pre><code>class Book: def __init__(self, title, author, pages): self.title = title self.author = author self.pages = pages self.checkedOut = False def checked_Out(self): print(self.checkedOut) # it has to be the instance variable return self.checkedOut def change_value_of_checkedOut(self): if self.checkedOut == False: self.checkedOut = True print("Switched from False to True.") elif self.checkedOut == True: self.checkedOut = False print("Switched from True to False.") def return_pages(self): print(self.pages) return self.pages def return_title(self): print(self.title) return self.title class Library: def __init__(self): collection = {} def addExistingBook(self, book): collection[book.title] = book.author def addNewBook(self, title, author, pages): # create a book new_book = Book(title, author, pages) collection[title] = new_book.author # access the author def change_checked_out_status(self, title): if title in collection.keys(): title.change_value_of_checkedOut() else: print("This book is not in the collection.") </code></pre> <p>Then, add the rest in a <code>main</code> function:</p> <pre><code>def main(): # if you are using Python 2.x, change input() to raw_input() title = str(input("Enter the title of the book. ")) author = str(input("Enter the author of the book. ")) pages = int(input("Enter the number of pages in the book. ")) myBook = Book(title, author, pages) myLib = Library() myLib.addExistingBook(myBook) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload