process order

trying to use a function and return a value

Page 1 of 1

6 Replies - 15574 Views - Last Post: 22 October 2010 - 10:28 AM Rate Topic: -----

#1 evertron   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-February 09

process order

Posted 21 October 2010 - 08:58 PM

i get an error that int object is not callable with my code. I am using 2 value lists that I send to a function(process_order_item. I am not sure if I need to send a list to the function or the index like quantity[i]. My code is below.

 #process order item
#order item function
import pdb 
print "This program calculates a total after the user enters: \n the Item, Quantity and Price"
#define process function
def process_order_item(quantity,price):
    if quantity >= 10:
        discount = .03
        discounted = 0.0
        subtotal = quantity * price
        discounted = subtotal * discount
        subtotal  -= discounted
        print'>10 subtotal',subtotal
    else:
        subtotal = quantity * price
        print'>subtotal',subtotal
        
        return subtotal

#create lists for data
items_list = []
subtotal = 0.0
quantity_list = []
price_list = []
totlist = []
quantity = 0
price = 0
total = 0
discount = .03

#get user input
for i in range(0,2,1):
    item = str(raw_input('Enter an item: '))
    quantity = int(raw_input('How many of these do you want? '))
    price = int(raw_input('Enter the price: '))
    #append lists
    items_list.append(item)
    quantity_list.append(quantity)
    price_list.append(price)
  


print ('Item Name') + ' ' +('Quantity') + ' ' +  ('Price')
for i in range(0,2,1):
    process_order_item(quantity(i),price(i))
    print quantity[i], price[i] 


Is This A Good Question/Topic? 0
  • +

Replies To: process order

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: process order

Posted 22 October 2010 - 08:44 AM

Please copy and paste the exact error you are receiving.
Was This Post Helpful? 0
  • +
  • -

#3 evertron   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-February 09

Re: process order

Posted 22 October 2010 - 08:55 AM

Here is the error I get.

Traceback (most recent call last):
File "F:/Python_Stuff/CSC143-901/orderCodehelp", line 45, in <module>
process_order_item(quantity(i),price(i))
TypeError: 'int' object is not callable
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: process order

Posted 22 October 2010 - 09:23 AM

I think you want to be accessing the LISTS. You're getting the error because you are accessing the integer variables, not the list.
process_order_item(quantity_list[i],price_list[i])
print quantity_list[i], price_list[i]

Was This Post Helpful? 0
  • +
  • -

#5 evertron   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-February 09

Re: process order

Posted 22 October 2010 - 09:39 AM

Why does my function not return the value back to the main program code. I get zero for subtotal but my print statements in the function print out the right value but that value does not go back to subtotal on the code before I print it out.

 #process order item
#order item function

print "This program calculates a total after the user enters: \n the Item, Quantity and Price"
#define process function
def process_order_item(quantity,price):
    if quantity >= 10:
        discount = .03
        discounted = 0.0
        subtotal = quantity * price
        discounted = subtotal * discount
        subtotal  -= discounted
        print'>10 subtotal',subtotal
    else:
        subtotal = quantity * price
        print'<10 Qty. subtotal',subtotal
        
        return subtotal

#create lists for data
items_list = []
subtotal = 0.0
quantity_list = []
price_list = []
totlist = []
quantity = 0
price = 0
total = 0
discount = .03

#get user input
for i in range(0,2,1):
    item = str(raw_input('Enter an item: '))
    quantity = int(raw_input('How many of these do you want? '))
    price = int(raw_input('Enter the price: '))
    #append lists
    items_list.append(item)
    quantity_list.append(quantity)
    price_list.append(price)
  


print ('Item Name') + ' ' +('Quantity') + ' ' +  ('Price')

for i in range(0,2,1):
    process_order_item(quantity_list[i],price_list[i])
    print quantity_list[i], price_list[i], subtotal 

Was This Post Helpful? 0
  • +
  • -

#6 Nallo   User is offline

  • D.I.C Regular
  • member icon

Reputation: 165
  • View blog
  • Posts: 258
  • Joined: 19-July 09

Re: process order

Posted 22 October 2010 - 09:45 AM

Your function returns a value (return subtotal returns a value, not the variable subtotal), so you have to assign that returned value to a variable in your main programm:
...
for i in range(0,2,1):
    subtotal = process_order_item(quantity_list[i],price_list[i])
    print quantity_list[i], price_list[i], subtotal 


Was This Post Helpful? 0
  • +
  • -

#7 evertron   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-February 09

Re: process order

Posted 22 October 2010 - 10:28 AM

Ok thanks for the help everyone. I thought that the function would just send back the subtotal for the subtotal in the main program with the return statement.

Thanks Again,
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1