Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #106013 > unrolled thread

Calculate Bill

Started byYum Di <nevinadias3@gmail.com>
First post2016-03-29 15:33 -0700
Last post2016-03-30 11:19 +0100
Articles 4 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Calculate Bill Yum Di <nevinadias3@gmail.com> - 2016-03-29 15:33 -0700
    Re: Calculate Bill Chris Angelico <rosuav@gmail.com> - 2016-03-30 10:34 +1100
    Re: Calculate Bill Steven D'Aprano <steve@pearwood.info> - 2016-03-30 11:50 +1100
    Re: Calculate Bill BartC <bc@freeuk.com> - 2016-03-30 11:19 +0100

#106013 — Calculate Bill

FromYum Di <nevinadias3@gmail.com>
Date2016-03-29 15:33 -0700
SubjectCalculate Bill
Message-ID<ba29ab8f-1076-4a00-8b2e-b4bbe0fbae60@googlegroups.com>
import random
import time

print ("Welcome to Pizza Shed!")

order = raw_input ("\n\nPLEASE PRESS ENTER TO ORDER." )

tablenum = input ("Enter table number from 1-25 \n ")
while tablenum>25 or tablenum <=0:
    tablenum = input ("Enter the correct table number, there are only 25 tables ")
    
#Pizza menu with prices

print ("---------------------")

print ("Let me help you with your order!")

print ("---------------------")

order = raw_input ("\n\nPLEASE PRESS ENTER TO SELECT YOUR PIZZA." )

print ("Menu")

print (
    "1 = cheese and tomato: 3.50, "
    "2 = ham and pineapple: 4.20, "
    "3 = vegetarian: 5.20, "
    "4 = meat feast: 5.80, "
    "5 = seafood: 5.60 " )

pizza_choice = input("Enter the type of pizza that you want to order from 1-5 \n")
while pizza_choice>5 or pizza_choice <=1:
    pizza_choice = input ("Enter the right number ")
    
print ("------------------")

pizza_amount = input ("Enter the amount of Pizzas that you want to order ")
while pizza_amount > 10 or pizza_amount <=0:
    pizza_amount = input ("Maximum amount is 10, Please enter again ")

print ("--------------------")

#base

print ("Base")

print (
    "1 = thin and crispy,"
    "2 = traditional" )

base = input ("Select a base from 1-2 \n")
while base>2 or base<=1:
    base = input ("There are only 2 types, Please enter again ")

if base == 1:
    print "You have chosen thin and crispy"
elif base == 2:
    print ("You have chosen traditional")
    
print ("-------------------")

#extra toppings

print ("Extra Toppings")

toppings = input ("Enter a number for your choice of extra topping \n Enter 1 for extra cheese \n Enter 2 for extra pepperoni \n Enter 3 for extra pineapple \n Enter 4 for extra peppers \n" )
while toppings >4 or toppings < 0:
    toppings = input ("There are only 4 types of extra toppings, Please try again " )

if toppings == 1:
    print "You have chosen extra cheese"
elif toppings == 2:
    print ("You have chosen pepperoni")
elif toppings == 3:
    print ("You have chosen pineapple")
elif toppings == 4:
    print ("You have chosen peppers")

print ("-------------------------")

#drink

print ("Drink")

print (
    "1 = Cola: 0.90, "
    "2 = Lemonande: 0.80, "
    "3 = Fizzy Orange: 0.90 "
    )

drink = input ("Enter a number for your choice of drinks " )
while drink>3 or drink<0:
    drink = input ("Choices start from 0 to 3 " )
drink_amount = input ("Enter the amount of drinks")
while drink_amount >10 or drink_amount<1:
    drink_amount = input (" You can only have upto 10 drinks, Please try again")

if drink == 1:
    print "You have chosen Cola"
elif drink == 2:
    print ("You have chosen Lemonande")
elif drink == 3:
    print ("You have chosen Fizzy Orange")

print ("--------------------------------")
print ("Calculating bill")
print ("--------------------------------")
print ("--------------------------------")

print ("Thank You for ordering at Pizza Shed! ")

Hey.. this code works. However, i need it to calculate the total cost.
I dont know how to do that. Can someone help me..
thanks

[toc] | [next] | [standalone]


#106016

FromChris Angelico <rosuav@gmail.com>
Date2016-03-30 10:34 +1100
Message-ID<mailman.171.1459294472.28225.python-list@python.org>
In reply to#106013
On Wed, Mar 30, 2016 at 9:33 AM, Yum Di <nevinadias3@gmail.com> wrote:
> Hey.. this code works. However, i need it to calculate the total cost.
> I dont know how to do that. Can someone help me..
> thanks

It does indeed appear to work. And thank you for posting your current
code. However...

> print ("Welcome to Pizza Shed!")
>
> order = raw_input ("\n\nPLEASE PRESS ENTER TO ORDER." )
>
> tablenum = input ("Enter table number from 1-25 \n ")

This should never be done. Do not do this. Your use of raw_input
proves that you're using Python 2, and in Python 2, never ever ever
use input(). There are two solutions:

1) Use raw_input everywhere
2) Use Python 3, and add parentheses to the few print() calls that
don't have them.

Either way, the correct fix also involves accepting *strings* from the
keyboard, and then converting them. The problem with input() is that
it automatically converts what the user types, according to the rules
of source code; you almost never want this. For example, entering 08
will result in an error, but 08.50 is the same as 8.50.

After that, you can start looking at the totals. But I'm not going to
write the code for you; you can start writing code, and when you get
stuck, come and ask for help.

ChrisA

[toc] | [prev] | [next] | [standalone]


#106021

FromSteven D'Aprano <steve@pearwood.info>
Date2016-03-30 11:50 +1100
Message-ID<56fb22e8$0$1601$c3e8da3$5496439d@news.astraweb.com>
In reply to#106013
On Wed, 30 Mar 2016 09:33 am, Yum Di wrote:


[...]
> print ("Thank You for ordering at Pizza Shed! ")
> 
> Hey.. this code works. However, i need it to calculate the total cost.
> I dont know how to do that. Can someone help me..
> thanks


Think about how people calculate the bill at a real pizza restaurant.

Every time you order something, they write it down in a list:

seafood
thin and crispy
extra cheese
pineapple
Fizzy Orange


The list goes to the cook, who prepares the order, then when you're ready to
pay, it goes to somebody who works out the prices.

In your case, you don't need to care about the cook. So you can record the
prices of each item in a list:


prices = []  # No items have been ordered.

# Order 3 seafood pizzas:

prices.append(5.60 * 3)

and so on, for all the extra topics, drinks, deserts, anything else they
order.

Then, you calculate the total:

sum(prices)



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#106041

FromBartC <bc@freeuk.com>
Date2016-03-30 11:19 +0100
Message-ID<ndg914$m0d$1@dont-email.me>
In reply to#106013
On 29/03/2016 23:33, Yum Di wrote:

> print ("Menu")
>
> print (
>      "1 = cheese and tomato: 3.50, "
>      "2 = ham and pineapple: 4.20, "
>      "3 = vegetarian: 5.20, "
>      "4 = meat feast: 5.80, "
>      "5 = seafood: 5.60 " )

> Hey.. this code works.

Sure, after you got rid of those list that were causing the trouble!

  However, i need it to calculate the total cost.
> I dont know how to do that. Can someone help me..
> thanks

But I think you will need a list of some sort as central place to store 
descriptions and prices. Several lists actually for the different menus. 
There are a dozen ways to this. One simple approach is below.

pizzas=( ("Cheese and Tomato", 3.50),  #0
          ("Ham and Pineapple", 4.20,), #1
          ("Vegetarian",5.20),          #2
          ("Meat Feast",5.80),          #3
          ("Seafood",5.60))             #4

descr = 0        # indices into each record
cost  = 1

def showmenu(menu):
     for number,selection in enumerate(menu,1):
         print ("{:>3} {:30} {:3.2f}".format(number,
                selection[descr],selection[cost]))

showmenu(pizzas)

option   = 3-1        # vegetarian (3 on displayed menu is 2 in list)
quantity = 2

print ("You chose",quantity,"of",pizzas[option][descr])
print ("Total is",pizzas[option][cost]*quantity)

-- 
Bartc

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web