Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

I keep getting syntax error?

syntax errorpython if else statement

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 MelanieMariaBlume

MelanieMariaBlume

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 14 March 2016 - 07:29 PM

Hi everybody 

    Im haveing a problem with a syntax error, it registers a portion and then tells me syntax error then highlights in red part of the else if statement. i have retyped that section and if keeps telling me error. so if you one would help i would greatly appreciate it.  this is the first computer language im learning. 

 

its the first elif that is what is registering the error.

def main():    endProgram = ("no")
    print
    while endProgram == ("no"):
        totalBurger = 0
        totalFry = 0
        totalSoda = 0
        endOrder = ("no")
    while endOrder == ("no"):
         print
         print ("Enter 1 for Yum Yum Burger")
         print ("Enter 2 for Grease Yum Fries")
         print ("Enter 3 for Soda Yum")
         option = input('Enter now ->')
         if option == 1:
                    totalBurger = getBurger(totalBurger)
                    elif option == 2:
                        totalFry = getFry(totalFry)
                        elif option == 3:
                            totalSoda = getSoda(totalSoda)
                            else:
             print ("You have entered an invalid option!!!")


         endOrder = raw_input("Do you want to end your order? (Enter yes or no): ")
     print
     total = calcTotal(totalBurger, totalFry, totalSoda)
     printReceipt(total)


     endProgram = raw_input("Do you want to end program? (Enter no to process a new order): ")
             
def getBurger(totalBurger):
burgerCount = input("Enter the number of burgers you want ")
totalBurger = totalBurger + burgerCount * .99
return totalBurger


def getFry(totalFry):
fryCount = input('Enter the number of fries you want ')
totalFry = totalFry + fryCount * .79
return totalFry


def getSoda(totalSoda):
sodaCount = input('Enter the number of sodas you want ')
totalSoda = totalSoda + sodaCount * 1.09
return totalSoda


def calcTotal(totalBurger, totalFry, totalSoda):
subtotal = totalBurger + totalFry + totalSoda
tax = subtotal * .06
total = subtotal + tax
return total


def printReceipt(total):
print ("The total price is $", total)


main() >





Edited by MelanieMariaBlume, 14 March 2016 - 07:30 PM.


#2 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts

Posted 09 April 2016 - 11:19 AM

Your indentation is wrong.

if thing:
    do something
elif other thing:
    do something else
else:
    whatever

sudo rm -rf / && echo $'Sanitize your inputs!'