def put(self, item): """If the knapsack is untied, use the Backpack put() method.""" if self.closed: print "Knapsack is closed!" else: Backpack.put(self, item)
# name this file 'solutions.py' """Volume II Lab 2: Object Oriented Programming Drew Pearson Class 321 9/10/15 """ import math from Backpack import Backpack my_backpack = Backpack() your_backpack = Backpack() my_backpack.put('tape') my_backpack.put('scissors') your_backpack.put('tape') my_backpack = your_backpack # Problem 1: Modify the 'Backpack' class in 'Backpack.py'. # Study the 'Knapsack' class in 'Backpack.py'. You should be able to create a # Knapsack object after finishing problem 1. # Problem 2: Write a 'Jetpack' class that inherits from the 'Backpack' class. class Jetpack(Backpack): """A Jetpack object class. Inherits from the Backpack class. However, it's initial color is silver and its initial max size is 2. A jetpack class also has an additional attribute - feul (int) which if not given is preset to 10. """ def __init__(self, color='silver', name='jetpack', max_size=2, fuel=10):