0

I want to write script to calculate the volume. The first function calculates area of the base. The second takes this value and multiply it with the height. Then I'd like to write the value of the volume. Where is the mistake?

def base_area(a, b):
    a = 2
    b = 3
    s = a * b
    return s

def volume(s):
    h = 7
    V = h * s
    print (V)
4
  • 1
    Why do you think there's a mistake? Commented Feb 23, 2014 at 22:41
  • You are not calling either function, for starters. Not in the code posted here in any case. Commented Feb 23, 2014 at 22:43
  • You probably don't want to define what a and b are inside your base_area function, as those are already given as arguments to it. So remove the first two lines of that function. Commented Feb 23, 2014 at 22:44
  • sorry I the script is not complete. I don't know how to call the function to write the Volume. If I write volume(V) it says that V is unknown. Commented Feb 23, 2014 at 22:44

1 Answer 1

2

It doesn't make sense to pass a, b as parameters to base_area() function, because inside, you are assigning constant values to a and b. That method should look like:

def base_area(a, b):
    s = a * b
    return s

so you use the values passed. This function can be written in a more concise way:

def base_area(a, b):
    return a * b

Then the volume() method should receive 3 parameters, a, b and h(height):

def volume(a, b, h):
    return base_area(a, b) * h

Here, you are calling base_area() passing a and b. From this call, you get the area, so you multiply it by h and return it.

Test:

print volume(2, 3, 7)
>>> 42
Sign up to request clarification or add additional context in comments.

Comments