Question: Can you please look at my python code and tell me the problem? (and the solution) every thing seems fine but it does not run.
Can you please look at my python code and tell me the problem? (and the solution) every thing seems fine but it does not run.
The whole question is this but my code is for number 1 :
Create a python program that imitates a schoolbag containing two binders. The program should contain three classes: Binder, SchoolBag and BagTester (which consists of the main method).
- The Binder class.
- Create all the necessary instance fields for the class. Each Binder object should keep track the following information:
- Label
- Color
- Number of sheets of paper in the binder
- Create the class constants for the class:
- Weight of each sheet of paper
- Weight of an empty binder
- Create all the necessary methods. Each Binder object should perform the following tasks:
- Add sheets to the binder
- Calculate the total weight of the binder (with the sheets in it)
- Comparing the weight of the implicit and explicit binder
- Allows the capability to print info about the binder
- Create a constructor that initializes the instance variables of the object being constructed.
- Create all the necessary instance fields for the class. Each Binder object should keep track the following information:
- The SchoolBag class:
- A schoolbag has a style (String) and consists of two binders. Create the instance fields accordingly.
- Create the class constants for the class:
- Weight of the empty schoolbag
- Create the methods that perform the following tasks:
- Add sheet(s) to given binder (specified by id / index)
- Remove sheet(s) from given binder
-
- Calculate the average weight of a binder in the bag
- Calculate the total weight of the schoolbag (with the binders)
- Allows the capability to print info about the schoolbag
- Create two constructors:
- The first one takes two object reference parameters. The two objects will be the two binders. The object must already exist before using this constructor.
- The second one takes as parameters all the information of the two binders. The two binders will be created in the constructor and assigned to the corresponding fields.
- Create a BagTester class that performs the following:
- Prompt user for information of two school bags and their content
- Create two instances of school bag. Use different constructors to create each instance
- Continue to prompt user for the following until -1 is entered for ID
- ID for a schoolbag
- ID for a binder in the schoolbag
- Add or remove sheets
- The number of sheets
- Print out the information of each schoolbag
And my code for it is :
class binder:
def __init__ (self,label,color,sheets):
self.__label = label
self.__color = color(black,blue, pink)
self.__sheets = sheets
def labels(self):
return self.__label
def colors (self):
return self.__color
def sheets (self):
return self.__sheets
num=0
ask=int(input("How many pages would you like to add?"))
if ask ==0:
return num
else:
print(num+ask)
sheets(sheets)
class constants:
input2 = float(input("How many papers does you binder have?"))
def __init__ (self, weightp, weightb):
self.__weightp = weightp
self.__weightb = weightb
def weightpapers (self):
return self.__weightp
if input2 == 0:
print ("The weight is 10 grams")
else:
weight = input2*0.045
print ("The weight is {} grams".format(weight1))
def weightbinder(self):
return self.__weightb
weight1= input2*0.045
totalweight=weight1+10
print ("The weight is {} grams".format(weight))
weightpaper()
weightbinder()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
