Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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; 'elif': 0.04; '(even': 0.05; '---------': 0.05; 'much!': 0.05; 'badly': 0.07; 'false,': 0.07; 'ok.': 0.07; 'over,': 0.07; 'referring': 0.07; 'subject:help': 0.07; '"but': 0.09; '"yes"': 0.09; "'n'": 0.09; '[1,': 0.09; 'agree,': 0.09; 'answering': 0.09; 'be:': 0.09; 'correct,': 0.09; 'item,': 0.09; 'to:addr:comp.lang.python': 0.09; 'url:github': 0.09; 'cc:addr:python-list': 0.10; 'assume': 0.11; 'value.': 0.15; '"2"': 0.16; '"2":': 0.16; '"n"': 0.16; '"while"': 0.16; '"y")': 0.16; '1):': 0.16; '2):': 0.16; '3):': 0.16; 'advice:': 0.16; 'already,': 0.16; 'better):': 0.16; 'boolean': 0.16; 'cares': 0.16; 'eval': 0.16; 'fine.': 0.16; 'hint': 0.16; 'saver': 0.16; 'say.': 0.16; 'sense,': 0.16; 'set:': 0.16; 'such,': 0.16; 'trivia': 0.16; 'twice.': 0.16; '\xa0this': 0.16; 'later': 0.16; 'wrote:': 0.17; 'figures': 0.17; 'skip': 0.17; 'changes': 0.20; 'followed': 0.20; 'question.': 0.20; 'sort': 0.21; 'all,': 0.21; 'meant': 0.21; 'assumes': 0.22; 'back.': 0.22; 'combination': 0.22; 'finally,': 0.22; 'planet': 0.22; 'wednesday,': 0.22; '\xa0if': 0.22; 'errors': 0.23; 'sets': 0.23; 'somebody': 0.23; 'statement': 0.23; "i've": 0.23; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'skip:[ 10': 0.26; 'select': 0.26; 'cc:addr:gmail.com': 0.27; 'question': 0.27; 'functions.': 0.27; 'regular': 0.27; "doesn't": 0.28; 'lines': 0.28; 'this?': 0.28; 'run': 0.28; 'post': 0.28; 'sensible': 0.29; 'thus,': 0.29; 'types.': 0.29; 'probably': 0.29; 'this.': 0.29; "i'm": 0.29; 'normally': 0.30; 'unlike': 0.30; 'button': 0.30; 'figure': 0.30; 'seconds': 0.30; 'stuff': 0.30; 'code': 0.31; 'gets': 0.32; 'december': 0.32; 'generally': 0.32; 'good.': 0.32; 'could': 0.32; 'anywhere': 0.33; 'choices': 0.33; 'defining': 0.33; 'int': 0.33; 'much.': 0.33; 'true.': 0.33; 'problem': 0.33; 'knowledge': 0.33; 'code:': 0.33; 'that,': 0.34; "can't": 0.34; 'changed': 0.34; 'received:google.com': 0.34; 'done': 0.34; 'false': 0.35; 'said,': 0.35; 'so,': 0.35; 'total': 0.65; 'offer': 0.65; '26,': 0.65; 'else.': 0.65; '8bit%:10': 0.69; 'business': 0.70; '3-4': 0.71; 'death': 0.71; 'day': 0.73; 'products.': 0.74; '10%': 0.81; '$50': 0.84; '(customer': 0.84; '(total': 0.84; 'basically,': 0.84; 'deserves': 0.84; 'movie,': 0.84; 'ordered.': 0.84; 'start.': 0.84; 'true!': 0.84; 'wars': 0.84; 'your:': 0.84; 'subject:you': 0.88; 'discount': 0.89; 'customer:': 0.91; 'does?': 0.91; 'received:209.85.213.184': 0.91; 'shopping?': 0.91 Newsgroups: comp.lang.python Date: Wed, 26 Dec 2012 16:19:08 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=76.125.254.81; posting-account=Dxm6hQoAAAAHopJagR5YUBCVOKa9jpIP References: <7333128a-6866-4e3c-8436-d5b2397beadc@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 76.125.254.81 MIME-Version: 1.0 Subject: Re: Please help if you can! From: bobflipperdoodle@gmail.com To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list , bobflipperdoodle@gmail.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: , Message-ID: Lines: 529 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356570019 news.xs4all.nl 6957 [2001:888:2000:d::a6]:48308 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35560 I cannot tell you how grateful I am that you took the time to do all of thi= s. I have been working on it all day and you are a better teacher in a few= minutes than my teacher has been in 4 months. THANK YOU! And thank you again, Mitya. I really appreciate your time and effort too! = Someday I'll be advanced enough to understand it lol I'm going to take a break and work on it more tomorrow. I'll be back. Thank you! On Wednesday, December 26, 2012 6:57:39 PM UTC-5, Joshua Landau wrote: > THIS IS A LONG POST, BUT IF YOU WANT TO LEARN YOU SHOULD READ IT. SERIOUS= LY. >=20 >=20 > UNLIKE Mitya Sirenef's THIS DOES NOT ASSUME MORE KNOWLEDGE THAN IS IN YOU= R POST ALREADY, ALTHOUGH HIS IS=A0DEFINITELY=A0BETTER OVERALL. AS SUCH, THE= RE ARE NO FUNCTIONS. >=20 >=20 >=20 > OK. There are several small errors in here, but there's nothing too large= or worth much worry. >=20 >=20 >=20 > On 26 December 2012 21:40,=A0=A0wrote: >=20 >=20 > I really hope you can help! >=20 > I need to create a program where the user can order any combination and q= uantity of 3 products. I then offer a 10% discount if the customer correctl= y answers a trivia question. =A0After that, there are 3 choices for shippin= g. >=20 >=20 >=20 > I have most of the program completed but I'm struggling with the most imp= ortant parts :/ =A0I get the total of multiple orders of the same item, but= we can't figure out how to total the entire order - before discounts and s= hipping - and then where to put any code referring back to the trivia quest= ion. Can somebody please help me with this? I would really appreciate it! >=20 >=20 >=20 >=20 >=20 > You write that you "need" to do this, which may hint that this is some so= rt of homework. If so, it's generally a nice thing to say as much. That sai= d, as long as you've given a good shot at it it's normally fine. >=20 >=20 > =A0This is the code: >=20 >=20 >=20 >=20 >=20 > My *very first* thought about this code is that it's really badly spaced.= Don't put lines together so much! [https://gist.github.com/4383950] shows = how much nicer things look when they're partitioned more. You may not agree= , but it took about 10 seconds and I prefer it. >=20 >=20 > =A0shop_again =3D 'y' >=20 >=20 >=20 >=20 >=20 > Hold on! Hold on! > shop_again should have a True/False value. It is screaming to be a boolea= n. "y" is a letter, not a boolean. Thus: >=20 >=20 > shop_again =3D True >=20 >=20 >=20 >=20 > This is important because you don't really want to get confused with all = your types. What if shop_again was later changed to be True when a button w= as clicked. Why on earth would you set it to "y"? You'd set it to True. Thu= s, the sensible option is to have your types right from the very start. >=20 >=20 >=20 > print("Welcome to the Star Wars Shop!") >=20 >=20 > customer =3D eval(input("Is there a customer in line? (1 =3D yes, 2 =3D n= o)> ")) >=20 >=20 >=20 > eval(input(TEXT)) is a *bad* idea. >=20 >=20 > First of all, eval is really dangerous. Answer "yes" instead and it'll ju= st crash. Answer True and it'll run... BUT do *neither* the if or the elif!= That's *bad*. >=20 >=20 > Secondly, you don't need it. Your: >=20 >=20 > "if(customer =3D=3D 1)" could be "if(customer =3D=3D '1')", which would w= ork without the eval. >=20 >=20 > And then you've got the standard of "Y/N". So a better question would be: >=20 >=20 >=20 >=20 > customer =3D input("Is there a customer in line? [Y/N]> ") >=20 >=20 > Finally, you want to accept "Y" *and* "y", so you'd really want: >=20 >=20 >=20 >=20 > customer =3D input("Is there a customer in line? [Y/N]> ").lower() >=20 >=20 >=20 > --------- > customer =3D input("Is there a customer in line? [Y/N]> ").lower() >=20 >=20 >=20 > Because customer really deserves to be boolean [True/False], you'd want t= o change it immediately. >=20 >=20 > customer =3D (customer =3D=3D "y") >=20 >=20 > This second line assumes that all non-"y"s are False, but that's a folly = you'll have to live with for now. >=20 >=20 >=20 > while shop_again =3D=3D 'y': >=20 >=20 >=20 >=20 >=20 > If you've changed shop_again to be boolean: >=20 >=20 > while shop_again: > =A0 > Some people don't get how this line would make sense. But it does. The "w= hile" statement only cares if it's value it gets is "truthy". Here are lots= of truthy things: >=20 >=20 >=20 >=20 > "y" =3D=3D "y" > True > False =3D=3D False > not False > "egg loaf" > [1, 2, 1, False, False] >=20 >=20 > and here are some falsy things: >=20 >=20 >=20 >=20 > "n" =3D=3D "y" > False > True =3D=3D False > not True > "" > [] >=20 >=20 > If this makes no sense, please just say. >=20 >=20 >=20 > =A0 =A0 if (customer =3D=3D 2): >=20 >=20 >=20 >=20 >=20 > Again, if you've done my changes from above: >=20 >=20 >=20 > if not customer: > =A0 >=20 > =A0 =A0 =A0 =A0 print("Welcome to the Star Wars Memorabilia Shop!") > =A0 =A0 =A0 =A0 customer =3D eval(input("Is there a customer in line? (1 = =3D yes, 2 =3D no)> ")) >=20 >=20 >=20 > Again: >=20 >=20 >=20 >=20 > customer =3D input("Is there a customer in line? [Y/N]> ").lower() >=20 > customer =3D (customer =3D=3D "y") >=20 > =A0 > BUT HOLD ON! >=20 >=20 > Run your program and then answer "2" twice. What happens? It's not good. >=20 >=20 >=20 >=20 > The problem is that answering "2" to this second one doesn't skip the loo= p! >=20 >=20 > x =3D ASK > LOOP: > =A0 =A0 if not x: > =A0 =A0 =A0 =A0 ASK > =A0 =A0 if x: >=20 >=20 > =A0 =A0 =A0 =A0 STUFF > =A0 =A0 MORE STUFF >=20 >=20 > Where you want: >=20 >=20 >=20 > x =3D ASK > LOOP: > =A0 =A0 if not x: > =A0 =A0 =A0 =A0 ASK > =A0 =A0 if x: > =A0 =A0 =A0 =A0 STUFF >=20 >=20 > =A0 =A0 =A0 =A0 MORE STUFF >=20 >=20 > or (even better): >=20 >=20 > while not x: > =A0 =A0 x =3D ASK > LOOP: > =A0 =A0 STUFF > =A0 =A0 MORE STUFF >=20 >=20 > The second is what I've just decided to call the "ask-until-yes" model. B= asically, you ask until you get a "yes", so you don't have to put the loop = anywhere else. By the time the first loop is over, you *know* that x is Tru= e! >=20 >=20 >=20 > =A0 =A0 elif (customer =3D=3D 1): >=20 >=20 >=20 >=20 >=20 >=20 > Again, if you've done my changes from above: >=20 >=20 >=20 > elif customer: > =A0 >=20 > =A0 =A0 =A0 =A0 print("Please select an item to update your order and any= other number to check out.") > =A0 =A0 =A0 =A0 print("Yoda Figure: $10 each.") > =A0 =A0 =A0 =A0 print("Star Wars Movie DVD: $20 each.") >=20 >=20 > =A0 =A0 =A0 =A0 print("Death Star Lego Set: $200 each.") > =A0 =A0 =A0 =A0 print(" 1 for Yoda Figure") > =A0 =A0 =A0 =A0 print(" 2 for Star Wars Movie DVD") > =A0 =A0 =A0 =A0 print(" 3 for Death Star Lego Set") >=20 >=20 > =A0 =A0 order =3D eval(input("Order: ")) >=20 >=20 >=20 > Again: >=20 >=20 > order =3D input("Order number: ") > =A0 >=20 > =A0 =A0 if (order =3D=3D 1): >=20 >=20 > If you've followed my advice: >=20 >=20 > if order =3D=3D "1": > =A0 >=20 > =A0 =A0 =A0 =A0 yoda =3D eval(input("How many Yoda Figures do you want? := ")) >=20 > =A0 =A0 =A0 =A0 total =3D 10 * yoda >=20 >=20 > Ooookkay. Now you're thinking: "BUT *surely* I need eval here!!(?)". >=20 >=20 > You don't. >=20 >=20 > yoda =3D int(input("How many Yoda Figures do you want? : ")) >=20 >=20 >=20 >=20 > This is better because there are so many problems with eval, and int also= means that you can only order whole numbers of yodas. > You probably also want to call this "number_of_yodas", because you're not= defining what "yoda" is. >=20 >=20 > =A0=A0 =A0 =A0 =A0 print("Total:", total) >=20 > =A0 =A0 =A0 =A0 print("Current order:", yoda, "at", total) >=20 > =A0 =A0 if (order =3D=3D 2): >=20 >=20 >=20 >=20 >=20 > If you've followed my advice: >=20 >=20 > if order =3D=3D "2": > =A0 >=20 > =A0 =A0 =A0 =A0 movie =3D eval(input("How many Star Wars Movie DVDs do yo= u want? : ")) >=20 > =A0 =A0 =A0 =A0 total =3D 20 * movie >=20 >=20 > As above: >=20 >=20 > number_of_movies =3D int(input("How many Star Wars Movie DVDs do you want= ? : ")) >=20 > total =3D 20 * number_of_movies=A0 >=20 >=20 >=20 > =A0 =A0 =A0 =A0 print("Total:", total) >=20 > =A0 =A0 =A0 =A0 print("Current order:", movie, "at", total) >=20 > =A0 =A0 if (order =3D=3D 3): >=20 >=20 >=20 >=20 >=20 > If you've followed my advice: >=20 >=20 > if order =3D=3D "3": > =A0 >=20 > =A0 =A0 =A0 =A0 legos =3D eval(input("How many Death Star Lego Sets do yo= u want? : ")) >=20 > =A0 =A0 =A0 =A0 total =3D 200 * legos >=20 >=20 >=20 > As above: >=20 >=20 > number_of_legos =3D int(input("How many Death Star Lego Sets do you want?= : ")) >=20 > total =3D 20 * number_of_legos >=20 >=20 > =A0=A0 =A0 =A0 =A0 print("Total:", total) >=20 > =A0 =A0 =A0 =A0 print("Current order:", legos, "at", total) >=20 >=20 >=20 >=20 > =A0 =A0 shop_again =3D input("Would you like to keep shopping? 'Y' for ye= s, 'N' for no: ") >=20 >=20 > Again: >=20 >=20 > shop_again =3D input("Would you like to keep shopping? [Y/N]> ").lower() >=20 >=20 >=20 > shop_again =3D (shop_again =3D=3D "y") > =A0 >=20 > =A0 =A0 print()print("Your order before shipping and discounts: ",total) >=20 > print() >=20 > print("Answer a trivia question for a discount!") >=20 > discount =3D eval(input("On what planet did Yoda live when Luke Skywalker= first met him? 1) Earth 2) Dagobah 3) Pluto :")) >=20 >=20 > Again: >=20 >=20 > discount =3D input("On what planet did Yoda live when Luke Skywalker firs= t met him? 1) Earth 2) Dagobah 3) Pluto :") >=20 >=20 >=20 > if (discount =3D=3D 1): >=20 > =A0 =A0 print("Sorry, that answer was wrong!") >=20 > if (discount =3D=3D 2):=A0 =A0 print("That's correct, you get a 10% disco= unt!") >=20 > if (discount =3D=3D 3): >=20 > =A0 =A0 print("Sorry, that answer was wrong!")=A0 >=20 >=20 > If you've taken my advice: >=20 >=20 > =A0if discount =3D=3D "1": > =A0 =A0 print("Sorry, that answer was wrong!") >=20 >=20 > if discount =3D=3D "2": > =A0 =A0 print("That's correct, you get a 10% discount!") > if discount =3D=3D "3": > =A0 =A0 print("Sorry, that answer was wrong!")=A0 >=20 >=20 > =A0print() >=20 > if (discount =3D=3D 2): >=20 >=20 > If you've taken my advice: >=20 >=20 >=20 > if discount =3D=3D "2": >=20 > =A0 >=20 > =A0 =A0 (total * .9) >=20 >=20 > Hold on! What do you think this line does? What is it meant to do? >=20 >=20 > You meant: >=20 >=20 > total =3D total*.9 >=20 >=20 > Which for clarity should be written: >=20 >=20 >=20 >=20 > total =3D total * 0.9 >=20 > =A0 >=20 > =A0 =A0 print("Your total before shipping: ",total)=A0 >=20 > =A0print("1) Regular Shipping: 3-4 business days, $5.00 per $50 ordered. = 2) Express Shipping: overnight, $10 per $50 ordered. 3) Super Saver Shippin= g: 7-10 business days, free.") >=20 > shipping =3D eval(input("Please select the shipping method you want: ")) >=20 >=20 >=20 >=20 > Again: > shipping =3D input("Please select the shipping method you want: ") >=20 >=20 >=20 > if (shipping =3D=3D 1): >=20 >=20 >=20 > If you've taken my advice: >=20 > Show original