-2

I have a little exercise I need to do in Python that's called "Desk Price Calculation". There need to be 4 functions which are used in the program.

My main problem is using the output of a function in another function.

def get_drawers():
    drawers = int(input('How many goddamn drawers would you like? '))
    return drawers

def get_wood_type():
    print('The types of wood available are Pine, Mahogany or Oak. For any other wood, type Other')
    wood = str(input('What type of wood would you like? '))
    return wood

def calculate_price(wood_type, drawers):
    wood_type = get_wood_type()
    drawers = get_drawers()
    wood_price = 0
    drawer_price = 0

    #wood price
    if wood_type == "Pine":
        wood_price = 100
    elif wood_type == "Oak":
        wood_price = 140
    elif wood_type == "Mahogany":
        wood_price = 180
    else:
        wood_price = 180

    #price of drawers
    drawer_price = drawers * 30

    return drawer_price + wood_price

def display_price(price, wood, drawer_count):
    price = calculate_price()
    wood = get_wood_type()
    drawer_count = get_drawers()

    print("The amount of drawers you requested were: ", drawer_count, ". Their total was ", drawer_count * 30, ".")
    print("The type of would you requested was ", get_wood_type(), ". The total for that was ", drawer_count * 30 - calculate_price(), ".")
    print("Your total is: ", price)

if __name__ == '__main__':

    display_price()
Loquitor
  • 19
  • 6
omar
  • 96
  • 1
  • 9

2 Answers2

0

I guess you get an error like this (that should have been added to your question by the way) :

Traceback (most recent call last):
  File "test.py", line 42, in <module>
    display_price()
TypeError: display_price() missing 3 required positional arguments: 'price', 'wood', and 'drawer_count'

You defined your display_price() function like this :

def display_price(price, wood, drawer_count):

So it expects 3 arguments when you call it, but you call it without any.

You have to either :

  1. redefine your function without argument (that would be the most logical solution since price, wood and drawer_count are defined in its scope.
  2. pass these arguments to the call of this function, but that would be useless for the reason I mentionned in 1. Unless you remove these arguments definition.

PS: You'll have the same problem with calculate_price() since it expects two arguments, but you pass none to it.

About function's arguments :

When you define a function, you also define the arguments it expects when you call it.

For instance, if you define :

def f(foo):
    # Do some stuff

a correct f call would be f(some_val) and not f()

Plus it would be useless to define f like this :

def f(foo):
    foo = someval
    # Do some other stuff

since foo is direcly redefined in the function's scope without even using the initial value.

This will help you to discover functions basics :

http://www.tutorialspoint.com/python/python_functions.htm

vmonteco
  • 14,136
  • 15
  • 55
  • 86
0

It would appear that you wanted to pass in some parameters to your method.

If that is the case, you need to move the "calculate" and "get" functions.

And, no need to re-prompt for input - you already have parameters

def calculate_price(wood_type, drawers):
    # wood_type = get_wood_type()
    # drawers = get_drawers()
    wood_price = 0
    drawer_price = 0

    # ... other calulations

    return drawer_price + wood_price

def display_price(wood, drawer_count):
    price = calculate_price(wood, drawer_count)

    ### Either do this here, or pass in via the main method below
    # wood = get_wood_type()
    # drawer_count = get_drawers()

    print("The amount of drawers you requested were: ", drawer_count, ". Their total was ", drawer_count * 30, ".")
    print("The type of would you requested was ", wood, ". The total for that was ", drawer_count * 30 - price, ".")
    print("Your total is: ", price)

if __name__ == '__main__':

    wood = get_wood_type()
    drawer_count = get_drawers()

    display_price(wood, drawer_count)
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245