Sep-02-2019, 12:56 AM
(This post was last modified: Sep-02-2019, 01:28 AM by ichabod801.)
I am trying to use a variable ordertotal to compute the total of an order with tax included in the code below. In the last line of my code I am trying to figure out why the ordertotal variable returns a zero value in this print statement: print('The total for your order comes to ${0:.2f} including tax. Have a nice day!'.format(float(ordertotal)))
If i put .format(float(sum(order) + (sum(order) * .043)) it computes correctly I just don't understand why if i use the variable ordertotal
it returns 0.
Here is the entire code below (look at the last line):
If i put .format(float(sum(order) + (sum(order) * .043)) it computes correctly I just don't understand why if i use the variable ordertotal
it returns 0.
Here is the entire code below (look at the last line):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
appetizers = { 'Chicken Wings' : 8.99 , 'Nachos' : 6.99 , 'Mozzarella Sticks' : 5.99 , 'Pretzels' : 5.99 , 'Onion Rings' : 4.99 , 'Cheeseburger Sliders' : 8.99 , 'Cheese Fries' : 8.99 } order = [] ordertotal = sum (order) + ( sum (order) * . 043 ) def mainmenu(): print ( "\n\tDan's Sports Bar Menu" ) print ( "\t1. Appetizers" ) print ( "\t2. Pizza" ) print ( "\t3. Burgers" ) print ( "\t4. Sandwiches" ) print ( "\t5. Desserts" ) food = input ( '\nPlease select one of the options above to view our menu selections:' ) if food = = '1' or food.casefold() = = 'appetizers' : print ( "\n\t\tAppetizers" ) print ( "\t1. Chicken Wings $8.99" ) print ( "\t2. Nachos $6.99" ) print ( "\t3. Mozzarella Sticks $5.99" ) print ( "\t4. Pretzels $5.99" ) print ( "\t5. Onion Rings $4.99" ) print ( "\t6. Cheeseburger Sliders $8.99" ) print ( "\t7. Cheese Fries $8.99" ) while True : appetizer = input ( 'Enter the menu number to select the appetizer you would like to order. To return to the main menu type main menu.' ) if appetizer = = 'main menu' : mainmenu() elif appetizer = = '1' : print ( 'You have placed on order for chicken wings.' ) order.append( float (appetizers[ 'Chicken Wings' ])) checkout = input ( 'Would you like to order another item on the menu? Type yes or no.' ) if checkout = = 'yes' or checkout = = 'y' : mainmenu() else : print ( 'The total for your order comes to ${0:.2f} including tax. Have a nice day!' . format ( float (ordertotal))) exit() |