[Tutor] Help with ebay profit/loss program error

Sam Klinger fire.fox005 at gmail.com
Tue Jul 19 22:46:21 CEST 2005

Hi my name is Sam Klinger and I made a smal program to help find out the
cost of listing and selling an item on ebay. However I see nothing wrong
with the code but I get these error messages:

1.   Insertion fee.
2.   Selling Fees.
7.   Quit.
type in a number (1-7): 1
What is the starting price?9
Traceback (most recent call last):
 File "C:/Documents and Settings/Sam/My Documents/Hacks/Python
Scripts/ebay_money.py", line 46, in ?
 File "C:/Documents and Settings/Sam/My Documents/Hacks/Python
Scripts/ebay_money.py", line 8, in compute_insertion_fee
   if price <= .99:
UnboundLocalError: local variable 'price' referenced before assignment

Here is the code to my program:
#gets the price of the item
def listing_price():
   price=input('What is the starting price?')

#Gets the seling price
def selling_price():
   selling=input('What was the selling price?')

#Computes the price of insertion
def compute_insertion_fee():
   if price <= .99:
       price= price+.25
   elif price <= 9.99:
       price= price=.35
   elif price <= 24.99:
       price= price=.60
   elif price <= 49.99:
       price= price=1.20
   elif price <= 199.99:
       price= price=2.40
   elif price <= 499.99:
       price= price=3.60
   elif price >= 500.00:
       price= price=4.80
   print price

#Computes the selling value
def compute_final_value():
   if selling == 0.00:
       print 'No fees'
   elif selling <= 25.00:
       selling= selling * .025
   elif selling <= 1000.00:
       selling= ((selling - 25.00) * .0275)+ 1.31
   elif selling >= 1000.00:
       selling= ((((selling - 25.00) - 1000.00) * .0150)+ 1.31+ 26.81)
   print selling

# Prints the menu
def print_menu():
   print '1.   Insertion fee.'
   print '2.   Selling Fees.'
   print '7.   Quit.'

#Gets a menu choice from user
while menu_choice !=7:
   menu_choice= input("type in a number (1-7): ")
   if menu_choice == 1:
   elif menu_choice == 2:
   elif menu_choice==7:

I could really use so help thanks!

More information about the Tutor mailing list