[Tutor] Help...
Christian Witts
cwitts at compuscan.co.za
Tue Jul 28 08:15:18 CEST 2009
Ryan V wrote:
> For this source code, i am getting some errors, and not sure how to
> fix it, as i am returning all the values. it is telling me that there
> is no value for the variables i am returning. any help is greatly
> appreciated!
> Source
> #main function
> def main():
> print 'The menu is:'
> print 'Yum Yum Burger for $0.99'
> print 'Grease Yum Fries for $0.79'
> print 'Soda Yum For $1.09'
> mealOrder = input_meal()
> burgerPrice = input_burger()
> friesPrice = input_fries()
> sodaPrice = input_soda()
> mealEnd = input_mealEnd()
> calc_total(burgerPrice, friesPrice, sodaPrice)
> # print_info(total)
>
> def input_meal():
> print 'If you want the Yum Yum Burger please press 1'
> print 'If you want the Grease Yum Fries please press 2'
> print 'If you want the Soda Yum please press 3'
> print 'If you entered no instead of yes just hit 4'
> mealOrder = input('Enter Now - ')
> if mealOrder == '1' :
> input_burger()
> elif mealOrder == '2' :
> input_fries()
> elif mealOrder == '3' :
> input_soda()
> elif mealOrder == '4' :
> calc_total(burgerPrice, friesPrice, sodaPrice)
>
> def input_burger():
> amountBurger = input('How many burgers would you like?')
> burgerPrice = amountBurger * 0.99
> input_mealEnd()
> return burgerPrice
>
> def input_fries():
> amountFries = input('How many Fries would you like?')
> friesPrice = amountFries * 0.79
> input_mealEnd()
> return friesPrice
>
> def input_soda():
> amountSoda = input('How many sodas would you like?')
> sodaPrice = amountSoda * 1.09
> input_mealEnd()
> return sodaPrice
>
> def input_mealEnd():
> mealEnd = raw_input('Would you like to end your order? (Enter yes
> or no)')
> if mealEnd == 'yes' :
> calc_total(burgerPrice, friesPrice, sodaPrice)
> elif mealEnd == 'no' :
> input_meal()
>
> #Calculation of meal cost
> def calc_total(burgerPrice, friesPrice, sodaPrice):
> totalFood = burgerPrice + friesPrice + sodaPrice
> totalTax = totalFood * .06
> total = totalTax + totalFood
> print 'The total price for food is $', totalFood
> print 'The Tax is $', totalTax
> print 'The total is $', total
> #Displays total, and what you ordered
> #def print_info(total):
> # print 'The meal price is $', total
>
> #call main function
> main()
> and here is the output i am getting
>
> The menu is:
> Yum Yum Burger for $0.99
> Grease Yum Fries for $0.79
> Soda Yum For $1.09
> If you want the Yum Yum Burger please press 1
> If you want the Grease Yum Fries please press 2
> If you want the Soda Yum please press 3
> If you entered no instead of yes just hit 4
> Enter Now - 1
> How many burgers would you like?2
> Would you like to end your order? (Enter yes or no)no
> If you want the Yum Yum Burger please press 1
> If you want the Grease Yum Fries please press 2
> If you want the Soda Yum please press 3
> If you entered no instead of yes just hit 4
> Enter Now - 2
> How many Fries would you like?2
> Would you like to end your order? (Enter yes or no)no
> If you want the Yum Yum Burger please press 1
> If you want the Grease Yum Fries please press 2
> If you want the Soda Yum please press 3
> If you entered no instead of yes just hit 4
> Enter Now - 3
> How many sodas would you like?2
> Would you like to end your order? (Enter yes or no)yes
> *Traceback (most recent call last):
> File "...", line 74, in <module>
> main()
> File "...", line 16, in main
> sodaPrice = input_soda()
> File "...", line 51, in input_soda
> input_mealEnd()
> File "...", line 57, in input_mealEnd
> calc_total(burgerPrice, friesPrice, sodaPrice)
> NameError: global name 'burgerPrice' is not defined*
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
You're caliing calc_total() in your input_mealEnd() function and in the
scope of that function there are no variables names burgerPrice,
friesPrice or sodaPrice.
--
Kind Regards,
Christian Witts
More information about the Tutor
mailing list