Define a class called Backpack
. The Backpack class should have a initializer method (aka constructor) which creates two instance...
X1265: BackpackClassPython
Define a class called Backpack
. The Backpack class should have a initializer method (aka constructor) which creates two instance variables: weight
and books
. Rember that instance variables are part of the self
object, and not just a local variable. For a newly-created backpack, its weight
is an integer and should be zero, while its books
should be an empty list.
Within the Backpack class, there should be a method called addBook
. That method will have two parameters: title
followed by weight
(three parameters if you are counting the self
parameter of methods). The weight should increase the weight of the backpack by the specified amount. The title should be appended to the end of the backpack's books list.
Your Answer:
Feedback
Your feedback will appear here when you check your answer.