Quoting Sam Klinger <[EMAIL PROTECTED]>:
> 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:
Hi Sam,
The problem is here:
> def listing_price():
> price=input('What is the starting price?')
This gets input from the user and stores it in a _local_ variable 'price'. When
the function terminates, the variable goes out of existence.
This means that, later on:
> #Computes the price of insertion
> def compute_insertion_fee():
> if price <= .99:
> price= price+.25
'price' does not exist, so you get the error you are seeing.
I recommend making use of the fact that functions can take parameters and can
return values. For example:
def listing_price():
price = float(raw_input('What is the starting price?'))
return price
def compute_insertion_fee(price):
if price <= 0.99:
# etc
#Gets a menu choice from user
menu_choice = 0
print_menu()
while menu_choice !=7:
menu_choice = int(raw_input("type in a number (1-7): "))
if menu_choice == 1:
price = listing_price()
compute_insertion_fee(price)
# etc
Incidentally: It is better to use raw_input, rather than input, for reasons that
have been discussed several times on this list recently :-)
--
John.
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor