Path: csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!news.qsc.de!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'elif': 0.05; 'output': 0.05; '"""': 0.07; 'subject:help': 0.08; 'coding:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '{},': 0.09; 'python': 0.11; 'jan': 0.12; '0.15),': 0.16; 'burger': 0.16; 'guys,': 0.16; 'menu:': 0.16; 'pizza': 0.16; 'price,': 0.16; 'reason.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'shorten': 0.16; 'statement.': 0.16; '{}"': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'written': 0.21; 'input': 0.22; 'select': 0.22; 'programming': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; '"you': 0.24; '2.x': 0.24; 'looks': 0.24; 'values': 0.27; 'header:X-Complaints- To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'along': 0.30; 'code': 0.31; 'selection': 0.32; '"the': 0.34; 'subject:the': 0.34; 'but': 0.35; 'there': 0.35; 'should': 0.36; 'list.': 0.37; 'follows:': 0.38; 'skip:. 20': 0.38; 'to:addr :python-list': 0.38; 'bill': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'solve': 0.60; 'new': 0.61; 'received:173': 0.61; 'subject:Need': 0.64; 'more': 0.64; 'total': 0.65; 'here': 0.66; 'price': 0.69; 'received:fios.verizon.net': 0.84; 'subject:below': 0.84; 'this...': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Need help to sort out the below code... Date: Sat, 14 Sep 2013 03:50:04 -0400 References: <9f6d4a88-4ae4-4e61-9f73-c074ec3f487f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 In-Reply-To: <9f6d4a88-4ae4-4e61-9f73-c074ec3f487f@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 91 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1379145023 news.xs4all.nl 15876 [2001:888:2000:d::a6]:48138 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54155 On 9/14/2013 2:34 AM, mnishpsyched wrote: > Hello guys, > i am new to programming and trying to solve this small coding: my purpose is to take in values from the user based on a menu provided for selection > > the output looks like this... > > please select from the following menu: > 1. pizza > 2. steak > 3. pasta > 4. burger > type in any number from above for selection.. > > you have selected: 1. Pizza > The bill amounted for Pizza is $20 along with tax of $0.15 will make upto $20.15 > > the code i have written for this is as follows: > > print """ > Please select from the following menu: > 1. pizza > 2. steak > 3. pasta > 4. burger > type in any number from above for selection.. > """ > > pz = raw_input() > pz = int(pz) > > st = raw_input() > st = int(st) > > ps = raw_input() > ps = int(ps) > > bg = raw_input() > bg = int(bg) > There should only be one input statement: choice = int(raw_input()) The program now requires 4 inputs, which is not what you want. Since you are starting, consider using 3.3 insteadd of Python 2 unless you have a very good reason. > if pz == 1 : if choice == 1: etc. > print "You have selected", pz, ".pizza" > pr_pz = 20 > tx_pz = 0.15 > tot = pr_pz + tx_pz > print "The bill amounted for Pizza is $", pr_pz, "along with tax of $", tx_pz, "willmake upto $", tot Take out 'amounted' > elif st == 2 : > print "You have selected", st, ".Steak" > pr_st = 40 > tx_st = 0.20 > print "The bill amounted for Steak is $", pr_st, "along with tax of $", tx_st, "will make upto $", tot..................... > ........................... > but my program doesn't output the selection once i type in any number from the list. Because it is waiting for 3 more inputs. See above. Now, you can shorten and improve the program after the one input statement. data = ( ('Pizza', 20.0, 0.15), ('Steak', 40.0, 0.20), ('Pasta', 14.0, 0.12), ('Burger', 23.0, 0.17), ) if 1 <= choice <= len(data): product, price, tax = data[choice] bill = "The bill for {} is {}, along with tax of {}, total {}" print(bill.format(product, price, tax, price + tax)) else: print('I do not know what you mean.') print() is for 3.x, but works here for 2.x also. -- Terry Jan Reedy