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 PointsThis isn't asking me how many burger, fries and sodas, I want and so the total is returning as $0.0, where am I wrong at
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
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. : ")
def 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, burgerCount, totalFries, fryCount, totalSoda, sodaCount, 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 = int(input("Enter how many burgers you would like, please."))
totalBurger = float(input(totalBurger + burgerCount * .99))
return totalBurger
def getFry(totalFries, fryCount):
fryCount = int(input("Enter how many fries you would like, please."))
totalFries = float(input(totalFries + fryCount * .79))
return totalFries
def getSoda(totalSoda, sodaCount):
sodaCount = int(input("Enter how many sodas you would like, please."))
totalSoda = float(input(totalSoda + sodaCount * 1.09))
return totalSoda
def calcTotal(totalBurger, totalFries, totalSoda, subtotal, tax, total):
subtotal = totalBurger + totalFries + totalSoda
tax = float(subtotal * .06)
total = subtotal + tax
return total
def printReceipt(total):
print("Your total is $ ", total)
main()
4 Answers
Steven Parker
243,658 PointsIt's obviously not taking your order or it would ask for quantities. That's because the input value is a string, but it is being compared to numbers. So instead of: if option == 1: you might write: if option == "1":
Also, in the code where you take in the quantities, "prompt" is being performed a second time with the numeric value as the argument. You probably don't want another "prompt" call there. Plus, there is some math being performed on the values before they are converted into floats. You can just convert the incoming strings into floats directly and skip the second conversion.
Cheri Castro
226 PointsPython 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information.
RESTART: C:\Users\0wner\Desktop\Programming logic\Python Labs\Lab 5-5.py
Enter 1 for Yum Yum burger : 1
Enter 2 for Grease Yum fries : 2
Enter 3 for soda Yum : 3
Enter yes to end order or no to continue the order. : yes
Your total is $ 0.0
Enter yes to end program or no to process another order. : yes
Here are the results I am getting.
Cheri Castro
226 PointsOk, thank you, I'll fix those.
Cheri Castro
226 PointsYou Are The Bomb!!!!! That was it! I have been struggling with this code trying to get everything to work right for weeks!!! It's for a school assignment. I had asked other students and the teacher, who had helped me unscramble some of the things that I had wrong but I've been stuck at this one point for at least a week, actually since I first signed up for treehouse and started the python classes on treehouse thinking that it might help me understand what I was doing wrong. Plus, I've been struggling so much with Python, I thought the treehouse method of teaching might help me understand it better. It has!!!! I'm still kind of slow going but two assignments that I hadn't completed because I was stuck I have them both completed now and finally I can move on to finishing another assignment that I was halfway through with. In addition, I am beginning to understand the mistakes that I'm making better. So, this all is becoming a little less frustrating. My schools method of teaching leaves a little to be desired, when it comes to how I am able to learn things.. I think I just learn differently. I thank you so much for your help! You're awesome!!!