Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106041
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | BartC <bc@freeuk.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Calculate Bill |
| Date | Wed, 30 Mar 2016 11:19:12 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 47 |
| Message-ID | <ndg914$m0d$1@dont-email.me> (permalink) |
| References | <ba29ab8f-1076-4a00-8b2e-b4bbe0fbae60@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Wed, 30 Mar 2016 10:16:04 -0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="cf45b3961a050227b1103bebc3cbc15a"; logging-data="22541"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+AhQpPIuHISudsCOLze3pi" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 |
| In-Reply-To | <ba29ab8f-1076-4a00-8b2e-b4bbe0fbae60@googlegroups.com> |
| Cancel-Lock | sha1:gB6FkAulksNYeyVjJm4tmO8gBjo= |
| Xref | csiph.com comp.lang.python:106041 |
Show key headers only | View raw
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
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
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
csiph-web