0

So I have a program that takes the value of an item.. checks the values with price then prints a result. Now my professor is asking for a 4th function that acts as a "data exchange" between the other 3 functions and act like a host for all the values and parameters to reside in. Here is what I currently have:

def quantity():
    count=raw_input("How many gearboxes would you like to order? ")
    return int(count)



def subtotal(count):
    if count<=10:
        cost=count*100.0
        return cost
    elif count>10 and count<20:
        cost=(count-10)*80.0+1000.0
        return cost
    elif count>20:
        cost=(count-20)*70.0+1000.0+800.0
        return cost

def summary(count, cost):
    print "="*80
    print "%60s %20f %20f" % ("motors",count,cost)
    print "="*80


items = quantity()
sub = subtotal(items)
summary(items, sub)

I guess where I am having trouble is knowing where to start creating a function that works as an exchange for the others. Any help is greatly appreciated. Thanks!

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by pyTony
0

That is curious request, usually that kind of role is only for classes not functions. You can treat any funcition as object (because they are) and you can add attributes to them, which are accessible from outside the function. Usually you use class or dictionary for that, though, except for memoization of functions.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.