Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Need help with a python code

  1. #1
    Join Date
    Aug 2009
    Location
    Tampa Fl
    Beans
    15
    Distro
    Ubuntu 6.10 Edgy

    Need help with a python code

    Hi I'm new to this site and also new to writting code. and am in school at ITT tech and I really need help with how to write a while code and get it running so far I can't get it to run and don't know why. Help!


    def main():
    endOrder = "no"
    while endOrder == "no":
    totalBurger = 0
    totatlFry = 0
    totalSoda = 0
    endOrder = 'no'

    while endOrder == 'no':
    print 'Enter 1 for Yum burger'
    print 'Enter 2 for Yum Fries'
    print 'Enter 3 for Yum soda'
    item = input ('Enter now -> ')
    if item == 1:
    totalBurger = getBurger (totalBurger)
    elif item == 2:
    totalFry = GetFry (totalFry)
    elif item == 3:
    totalSoda = getSoda (totalSoda)
    else:
    print 'try again'
    endOrder = raw_input ('Are you done with your order? ')
    totalBill = calcTotal (totalBurger, totalFry, totalSoda)
    print ('Your total bill is')

    def getBurger(totalBurger):
    burgerCount = input ('Enter the amount of Yum burgers You would like')
    Enter - 1
    print ('Enter the number of burgers you want')
    totalBurger = burgerCount + totalBurger * .99
    return totalBurger

    def getFry(totalFry):
    fryCount = input ('Enter the total number of fries you would like ')
    totalFry = fryCount + totalFry * .79
    return totalFry
    def getSoda(totalSoda):
    sodaCount = input ('Enter the total number of soda you would like ')
    totalSoda = sodaCount + totalSoda * 1.09
    return totalSoda
    def totalBill(totalBurger, totalFry, totalSoda):
    calcTotal = totalBurger + totalFry + totalSoda
    return totalBill
    main()

  2. #2
    Join Date
    Aug 2009
    Location
    Tampa Fl
    Beans
    15
    Distro
    Ubuntu 6.10 Edgy

    Question Re: Need help with a python code

    where are the Quick reply icons I don't see any on the page at all this is so frustrating!

  3. #3
    Join Date
    Dec 2007
    Location
    The last place I look
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Need help with a python code

    well first off, confirm that this is the correct indentation:
    Code:
    def main():
        endOrder = "no"
        while endOrder == "no":
            totalBurger = 0
            totatlFry = 0
            totalSoda = 0
        
            endOrder = 'no'
            while endOrder == 'no':
                print 'Enter 1 for Yum burger'
                print 'Enter 2 for Yum Fries'
                print 'Enter 3 for Yum soda'
                item = input ('Enter now -> ')
            if item == 1:
                totalBurger = getBurger (totalBurger)
            elif item == 2:
                totalFry = GetFry (totalFry)
            elif item == 3:
                totalSoda = getSoda (totalSoda)
            else:
                print 'try again'
                
            endOrder = raw_input ('Are you done with your order? ')
            
        totalBill = calcTotal (totalBurger, totalFry, totalSoda)
        print ('Your total bill is')
    
    def getBurger(totalBurger):
        burgerCount = input ('Enter the amount of Yum burgers You would like')
        Enter - 1
        print ('Enter the number of burgers you want')
        totalBurger = burgerCount + totalBurger * .99
        return totalBurger
    
    def getFry(totalFry):
        fryCount = input ('Enter the total number of fries you would like ')
        totalFry = fryCount + totalFry * .79
        return totalFry
    
    def getSoda(totalSoda):
        sodaCount = input ('Enter the total number of soda you would like ')
        totalSoda = sodaCount + totalSoda * 1.09
        return totalSoda
        
    def totalBill(totalBurger, totalFry, totalSoda):
        calcTotal = totalBurger + totalFry + totalSoda
        return totalBill
    
    main()

  4. #4
    Join Date
    Aug 2009
    Location
    Tampa Fl
    Beans
    15
    Distro
    Ubuntu 6.10 Edgy

    Re: Need help with a python code

    UMMM how do I do that? please

  5. #5
    Join Date
    Dec 2007
    Location
    The last place I look
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Need help with a python code

    since this is homework, I won't give you any code, but look closely at the error message. what does it say?

  6. #6
    Join Date
    Aug 2009
    Location
    Tampa Fl
    Beans
    15
    Distro
    Ubuntu 6.10 Edgy

    Re: Need help with a python code

    I indented but I get unexpected indent when I go to run it

  7. #7
    Join Date
    Dec 2007
    Location
    The last place I look
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Need help with a python code

    Quote Originally Posted by leedrew View Post
    UMMM how do I do that? please
    uhh, look at your code. does that look right?
    python uses indents for logic flow, but when you posted the code, you didn't put it in a code block so all the indentation was removed. what did the code look like when it still had indents?

    the easiest way would be to copy the code into a "code" block when you are posting it to the forum.
    Last edited by doas777; August 2nd, 2009 at 10:18 PM.

  8. #8
    Join Date
    Dec 2007
    Location
    The last place I look
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Need help with a python code

    Quote Originally Posted by leedrew View Post
    I indented but I get unexpected indent when I go to run it
    on what line? look at the line, and try to figure out what the message is complaining about.
    I use geany for python code. you can find it in the repositories.

    I have to ask, is this your code?

  9. #9
    Join Date
    Aug 2009
    Location
    Tampa Fl
    Beans
    15
    Distro
    Ubuntu 6.10 Edgy

    Re: Need help with a python code

    oh ok Like so ?

    def main():
    endOrder = "no"
    while endOrder == "no":
    totalBurger = 0
    totatlFry = 0
    totalSoda = 0
    endOrder = 'no'

    while endOrder == 'no':
    print 'Enter 1 for Yum burger'
    print 'Enter 2 for Yum Fries'
    print 'Enter 3 for Yum soda'
    item = input ('Enter now -> ')
    if item == 1:
    totalBurger = getBurger (totalBurger)
    elif item == 2:
    totalFry = GetFry (totalFry)
    elif item == 3:
    totalSoda = getSoda (totalSoda)
    else:
    print 'try again'
    endOrder = raw_input ('Are you done with your order? ')
    totalBill = calcTotal (totalBurger, totalFry, totalSoda)
    print ('Your total bill is')

    def getBurger(totalBurger):
    burgerCount = input ('Enter the amount of Yum burgers You would like')
    Enter - 1
    print ('Enter the number of burgers you want')
    totalBurger = burgerCount + totalBurger * .99
    return totalBurger

    def getFry(totalFry):
    fryCount = input ('Enter the total number of fries you would like ')
    totalFry = fryCount + totalFry * .79
    return totalFry
    def getSoda(totalSoda):
    sodaCount = input ('Enter the total number of soda you would like ')
    totalSoda = sodaCount + totalSoda * 1.09
    return totalSoda
    def totalBill(totalBurger, totalFry, totalSoda):
    calcTotal = totalBurger + totalFry + totalSoda
    return totalBill
    main()"

    Oh this is after doing some indenting but still get the unexpected indent message

  10. #10
    Join Date
    Oct 2008
    Beans
    561

    Re: Need help with a python code

    first off when posting code put it in code tags (the # symbol) makes it easier to read, and doesnt mess up python either (preserves white space)

    second you dont need 2 'while endOrder == 'no':' loops
    Last edited by benj1; August 2nd, 2009 at 10:21 PM.
    Check out my little app. Tnote

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •