I am getting the following error:Code:def main(): burgerCount = 0 friesTotal = 0 sodaTotal = 0 tax = 0 subTotal = 0 total = 0 order = getOrder() burgerCount = getBurger() subTotal = getSubTotal(burgerCount, friesTotal, sodaTotal) tax = getTax(subTotal) total = getTotal(subTotal, tax) def getOrder(): print ('Welcome to Yum Yum Burger.') print ('The menu is:') print ('Yum Yum Burger are $0.99') print ('Greasy Yum Fries are $0.79') print ('Soda Yum are $1.09') print ('Enter 1 for Yum Yum Burgers.') print ('Enter 2 for Greasy Yum Fries.') print ('Enter 3 for Soda Yum.') order = raw_input('Enter selection now. ') if order == '1': getBurger() elif order == '2': getFries() elif order == '3': getSoda() endOrder = raw_input ('Would you like to order anything else? Enter yes or no. ') if endOrder == 'no' : getSubTotal(burgerCount, friesTotal, sodaTotal) elif endOrder == 'yes' : getOrder() def getBurger(): burgerCount = input('How many Yum Yum Burgers would you like to order? ') burgerCount = burgerCount * 0.99 burgerCount = float(burgerCount) return burgerCount def getFries(): friesTotal = input('How many Greasy Yum Fries would you like to order? ') friesTotal = friesTotal * 0.79 friesTotal = float(friesTotal) return friesTotal def getSoda(): sodaTotal = input('How many Soda Yum would you like to order? ') sodaTotal = sodaTotal * 1.09 sodaTotal = float(sodaTotal) return sodaTotal def getSubTotal(burgerCount, friesTotal, sodaTotal): subTotal = burgerCount + friesTotal + sodaTotal subTotal = float(subTotal) return subTotal def getTax(subTotal): tax = subTotal * .06 tax = float(tax) return tax def getTotal(subTotal, tax): total = subTotal + tax total = float(total) return total def printInfo(): print ('The Subtotal for the order is $'), subTotal print ('The tax for the order is $'), tax print ('The total for the order is $'), total main()
Traceback (most recent call last):
File "E:\LAB 5.5.py", line 75, in <module>
main()
File "E:\LAB 5.5.py", line 8, in main
order = getOrder()
File "E:\LAB 5.5.py", line 33, in getOrder
getSubTotal(burgerCount, friesTotal, sodaTotal)
NameError: global name 'burgerCount' is not defined
Last edited by WingedPanther; 11-07-2009 at 12:15 PM. Reason: add code tags (the # button)
Please post this with [code][/code] tags instead of what you have right now. Python is literally unreadable without the whitespace since the whitespace is what determines when functions, loops, etc. end. Also, what is the problem you're facing?
Wow I changed my sig!
Please use code tags when posting code. It makes it much easier to read and you are more likely to get the help you're after.
This seems to be the same task as another poster was working on. You might want to read this thread for some hints. There's actually a complete solution in that thread, but you would be better off trying to improve your own code as you'll learn more this way.
The error you are getting is due to variable scope. You haven't defined burgerCount, friesTotal and sodaTotal outside of the the functions getBurgers() etc so main() cannot see them to pass to getSubTotal().
You need to assign the values returned by getBurgers() to a variable which can then be passed to getSubTotal(). You'll also need to do the same for getFries() and getSoda().
Where you have
you need something likeCode:if order == '1': getBurger() elif order == '2': getFries() elif order == '3': getSoda()
you can then pass these variables to getSubTotal()Code:if order == '1': burgers += getBurger() elif order == '2': fries += getFries() elif order == '3': soda += getSoda()
There are similar errors elsewhere in your code. For more information on variable scope have a look here.Code:subTotal = getSubTotal(burgers, fries, soda)
If there's a new way, I'll be the first in line.
But, it better work this time.
I dont think you understood what the return statement really does![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks