Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Cheri Castro
226 PointscalcTotal not defined, but after I defined it, I still get the error, calTotal not defined, what else am I doing wrong?
Traceback (most recent call last): File "python", line 90, in <module> File "python", line 37, in main NameError: name 'calcTotal' is not defined
def main(): endProgram = "no" endOrder = "no" totalBurger = 0 totalFries = 0 totalSoda = 0 subtotal = 0 tax = 0 total = 0 option = 0 burgerCount = 0 fryCount = 0 sodaCount = 0 calcTotal = 0
while endProgram == "no" :
totalBurger, totalSoda, totalFries, subtotal, tax, total = resetVariables()
while endOrder == "no" :
option = input("Enter 1 for Yum Yum burger : ")
if option == 1:
#call getBurger
totalBurger = getBurger(totalBurger, burgerCount)
elif option == 2:
totalFries = getFries(totalFries, fryCount)
while endOrder == "no" :
option = input("Enter 2 for Grease Yum fries : ")
if option == 2:
#call getFries
totalFries = getFries(totalFries, fryCount)
elif option == 3:
totalSoda = getSoda(totalSoda, sodaCount)
while endOrder == 'no' :
option = input("Enter 3 for soda Yum : ")
if option == 3:
#call getSoda
totalSoda = getSoda(totalSoda, sodaCount)
endOrder = input("Enter yes to end order or no to continue the order. : ")
total=calcTotal(totalBurger, totalFries, totalSoda, subtotal, tax, total)
printReceipt(total)
endProgram = input("Enter yes to end program or no to process another order. : ")
Cheri Castro
226 Pointsdef declareVariables (): endProgram = "no" endOrder = "no" totalBurger = 0 totalFries = 0 totalSoda = 0 total = 0 tax = 0 subtotal = 0 option = 0 burgerCount = 0 fryCount = 0 sodaCount = 0
return endProgram, endOrder, totalBurger, totalFries, totalSoda, subtotal, tax, total
def resetVariables(): totalBurger = 0 totalFries = 0 totalSoda = 0 subtotal = 0 tax = 0 total = 0
return totalBurger, totalSoda, totalFries, subtotal, tax, total
def getBurger(totalBurger, burgerCount): burgerCount = input("Enter how many burgers you would like, please.") totalBurger = totalBurger + burgerCount * .99 return totalBurger
def getFry(totalFries, fryCount): fryCount = input("Enter how many fries you would like, please.") totalFries = totalFries + fryCount * .79 return totalFries
def getSoda(totalSoda, sodaCount): sodaCount = input("Enter how many sodas you would like, please.") totalSoda = totalSoda + sodaCount * 1.09 return totalSoda
def calcTotal(totalBurger, totalFries, totalSoda, subtotal, tax, total): subtotal = totalBurger + totalFries + totalSoda tax = subtotal * .06 total = subtotal + tax return total
def printReceipt(total): print("Your total is $ ", total)
main()
Cheri Castro
226 PointsCheri Castro
226 PointsWow, after struggling with this for literally two weeks now, off and on, I think I've finally made some notable progress. Besides the above code, there's more, of course. I've been leery to turn my assignment in because I couldn't get everything to run right. After I'd fix a frustrating spacing issue then I'd end up with a new error. Now, I've finally got it to run top to bottom, sort of, it's still not quite right, because it is supposed to be completing some calculations after it gets some more info from the user, such as how many burgers do you want etc and then it is supposed to calculate the costs and tax and add it all into a neat little total and print it out for you. It's just coming back with $0.0 as the total and it isn't asking how many of anything that I want, so no true calculations are being completed. So, still more work to be done.