Hello I need help ASAP, my problem is due by thursday.....Here is the problem my teacher has given...

"Create a class that describes a box. The user should be able to submit the length, width, and height of a box. Also, you should include methods/functions to determine the surface area and volume of the box. Include any other methods you feel are necessary."

A very very Big THANK YOU in advance for spending the time in reading and then helping me solve it....
Thanx,
Posh..

The problem is that I was absent from the class for two weeks due to very bad health and have missed all the lectures and explanations and this week when I returned I came to know it was due this thursday and we have a test tomorrow on other two chapters. So I cannot even begin to imagine where to start ,except that i do know i have to finish!!!!
It sounds lame but ,I am 50 yrs and have recently become a single mom after 25 yrs and am hardworking and very serious in accomplishing my goals of getting out of this rut and doing better slowly but surely....

Here for debugging few test cases to get you started:

>>> b = Box(1,2,3)
>>> b.volume
6
>>> b.area
22
>>> b = Box(5,2,3)
>>> b.area
62
>>> b.volume
30
>>> 

Edited 4 Years Ago by pyTony

OK, let's start from the top:

  • Do you know how to declare a class?
  • Do you know how to write the constructor for a class? (Hint: in Python, the c'tor has to have a special name.)
  • How would you write a non-c'tor method? What is the first argument in a method in Python?
  • Given a class, do you know how to create an object?
  • How do you invoke a method of an object?
  • How would you calculate the surface area of a cube, if you had to do it by hand (hint: the surface of a cube consists of six squares)? How would you calculate it's volume (hint: they call raising a number to the 3rd power 'cubing' for a reason)?

Try to answer those questions, and apply the answers to the problem. If you don't know them, ask.

Edited 4 Years Ago by Schol-R-LEA

Hello ,
I am sorry I was buzzz trying to catch up with all other Homeworks so I could not come here.
We are using the Python Fundamentals Book by Kenneth Lambert.and I am OK upto chapter 2 after that everything seems to be tangent , I can understand a little bit but not much. especially the "for" loops and the "elif "statements etc.I need to understand that since that is the basics. Can you give me an idea as to how to tackle this monster...of "ignorance"...apart from reading it . i am a good reader ,but this is all VERY VERY new to me and I dont want to give up ...not yet...I have not given it my best yet....

Here is basic structure of class, you do not need loops or conditionals for this task so you can go through the python.org tutorial parallel while doing this home work. Here one example of simple class and using of a method.

class Person(object):
    def __init__(self, first, last):
        self.first = first
        self.last = last

    def last_first(self):
        return self.last + ', ' + self.first

cartoon = Person('Donald', 'Duck')
print cartoon.last_first()

Thanks ,I will work on it this afternoon and get started... Appreciate all your help...

This article has been dead for over six months. Start a new discussion instead.