Results 1 to 3 of 3

Thread: Help with python 2.6     submit to reddit submit to twitter

  1. #1
    Smells like Onions
    Join Date
    Nov 2009
    Posts
    1
    BG Level
    0

    Help with python 2.6

    I am getting an error when trying to run this.
    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

  2. #2
    Old Merits
    Join Date
    Jun 2008
    Posts
    1,203
    BG Level
    6
    FFXI Server
    Valefor

    ive never used python before, so im just going to pretend like i know it

    also needs more code tags


    all these lack of semicolons make me feel uncomfortable, i dont think im in my element.



    however, if py runs anything like any other language i know, burger count is not defined in the function "getSubTotal", it exists in the program but not in getSubTotal's scope. add burgerCount to getSubTotal's Arguments and it should work

    edit, im wrong. its not defined in getOrder, pass it on to getOrder as an argument so you can pass it on to getSubTotal. although i would rather have it go as so


    option = getOrder()
    if option = someoption {serveguy; getordersubtotal}

    in the main function, so not everything is being done in one function (you're deviating from its purpose, the way you're doing it you could/should do everything in main)

    i dont know if py supports switches but its the best way to do this, id rewrite the program but its against the rules, and considering the nomenclature (i love burgers, i hate talking about them) its a waste of time

    it also says that in the traceback. now get back to your homework.

  3. #3
    Old Merits
    Join Date
    Jun 2008
    Posts
    1,203
    BG Level
    6
    FFXI Server
    Valefor

    double: you could also declare burgercount as a global value, but its so incredibly dirty.

Similar Threads

  1. Replies: 8
    Last Post: 2010-02-20, 02:21