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


Groups > comp.lang.python > #35560

Re: Please help if you can!

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 <bobflipperdoodle@gmail.com>
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 <mailman.1305.1356566309.29569.python-list@python.org>
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> <mailman.1305.1356566309.29569.python-list@python.org>
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 <python-list@python.org>, 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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.1311.1356570019.29569.python-list@python.org> (permalink)
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

Show key headers only | View raw


I cannot tell you how grateful I am that you took the time to do all of this.  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. SERIOUSLY.
> 
> 
> UNLIKE Mitya Sirenef's THIS DOES NOT ASSUME MORE KNOWLEDGE THAN IS IN YOUR POST ALREADY, ALTHOUGH HIS IS DEFINITELY BETTER OVERALL. AS SUCH, THERE ARE NO FUNCTIONS.
> 
> 
> 
> OK. There are several small errors in here, but there's nothing too large or worth much worry.
> 
> 
> 
> On 26 December 2012 21:40, <bobflipp...@gmail.com> wrote:
> 
> 
> I really hope you can help!
> 
> I need to create a program where the user can order any combination and quantity of 3 products. I then offer a 10% discount if the customer correctly answers a trivia question.  After that, there are 3 choices for shipping.
> 
> 
> 
> I have most of the program completed but I'm struggling with the most important parts :/  I 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 shipping - and then where to put any code referring back to the trivia question. Can somebody please help me with this? I would really appreciate it!
> 
> 
> 
> 
> 
> You write that you "need" to do this, which may hint that this is some sort of homework. If so, it's generally a nice thing to say as much. That said, as long as you've given a good shot at it it's normally fine.
> 
> 
>  This is the code:
> 
> 
> 
> 
> 
> 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.
> 
> 
>  shop_again = 'y'
> 
> 
> 
> 
> 
> Hold on! Hold on!
> shop_again should have a True/False value. It is screaming to be a boolean. "y" is a letter, not a boolean. Thus:
> 
> 
> shop_again = True
> 
> 
> 
> 
> 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 was clicked. Why on earth would you set it to "y"? You'd set it to True. Thus, the sensible option is to have your types right from the very start.
> 
> 
> 
> print("Welcome to the Star Wars Shop!")
> 
> 
> customer = eval(input("Is there a customer in line? (1 = yes, 2 = no)> "))
> 
> 
> 
> eval(input(TEXT)) is a *bad* idea.
> 
> 
> First of all, eval is really dangerous. Answer "yes" instead and it'll just crash. Answer True and it'll run... BUT do *neither* the if or the elif! That's *bad*.
> 
> 
> Secondly, you don't need it. Your:
> 
> 
> "if(customer == 1)" could be "if(customer == '1')", which would work without the eval.
> 
> 
> And then you've got the standard of "Y/N". So a better question would be:
> 
> 
> 
> 
> customer = input("Is there a customer in line? [Y/N]> ")
> 
> 
> Finally, you want to accept "Y" *and* "y", so you'd really want:
> 
> 
> 
> 
> customer = input("Is there a customer in line? [Y/N]> ").lower()
> 
> 
> 
> ---------
> customer = input("Is there a customer in line? [Y/N]> ").lower()
> 
> 
> 
> Because customer really deserves to be boolean [True/False], you'd want to change it immediately.
> 
> 
> customer = (customer == "y")
> 
> 
> This second line assumes that all non-"y"s are False, but that's a folly you'll have to live with for now.
> 
> 
> 
> while shop_again == 'y':
> 
> 
> 
> 
> 
> If you've changed shop_again to be boolean:
> 
> 
> while shop_again:
>  
> Some people don't get how this line would make sense. But it does. The "while" statement only cares if it's value it gets is "truthy". Here are lots of truthy things:
> 
> 
> 
> 
> "y" == "y"
> True
> False == False
> not False
> "egg loaf"
> [1, 2, 1, False, False]
> 
> 
> and here are some falsy things:
> 
> 
> 
> 
> "n" == "y"
> False
> True == False
> not True
> ""
> []
> 
> 
> If this makes no sense, please just say.
> 
> 
> 
>     if (customer == 2):
> 
> 
> 
> 
> 
> Again, if you've done my changes from above:
> 
> 
> 
> if not customer:
>  
> 
>         print("Welcome to the Star Wars Memorabilia Shop!")
>         customer = eval(input("Is there a customer in line? (1 = yes, 2 = no)> "))
> 
> 
> 
> Again:
> 
> 
> 
> 
> customer = input("Is there a customer in line? [Y/N]> ").lower()
> 
> customer = (customer == "y")
> 
>  
> BUT HOLD ON!
> 
> 
> Run your program and then answer "2" twice. What happens? It's not good.
> 
> 
> 
> 
> The problem is that answering "2" to this second one doesn't skip the loop!
> 
> 
> x = ASK
> LOOP:
>     if not x:
>         ASK
>     if x:
> 
> 
>         STUFF
>     MORE STUFF
> 
> 
> Where you want:
> 
> 
> 
> x = ASK
> LOOP:
>     if not x:
>         ASK
>     if x:
>         STUFF
> 
> 
>         MORE STUFF
> 
> 
> or (even better):
> 
> 
> while not x:
>     x = ASK
> LOOP:
>     STUFF
>     MORE STUFF
> 
> 
> The second is what I've just decided to call the "ask-until-yes" model. Basically, 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 True!
> 
> 
> 
>     elif (customer == 1):
> 
> 
> 
> 
> 
> 
> Again, if you've done my changes from above:
> 
> 
> 
> elif customer:
>  
> 
>         print("Please select an item to update your order and any other number to check out.")
>         print("Yoda Figure: $10 each.")
>         print("Star Wars Movie DVD: $20 each.")
> 
> 
>         print("Death Star Lego Set: $200 each.")
>         print(" 1 for Yoda Figure")
>         print(" 2 for Star Wars Movie DVD")
>         print(" 3 for Death Star Lego Set")
> 
> 
>     order = eval(input("Order: "))
> 
> 
> 
> Again:
> 
> 
> order = input("Order number: ")
>  
> 
>     if (order == 1):
> 
> 
> If you've followed my advice:
> 
> 
> if order == "1":
>  
> 
>         yoda = eval(input("How many Yoda Figures do you want? : "))
> 
>         total = 10 * yoda
> 
> 
> Ooookkay. Now you're thinking: "BUT *surely* I need eval here!!(?)".
> 
> 
> You don't.
> 
> 
> yoda = int(input("How many Yoda Figures do you want? : "))
> 
> 
> 
> 
> 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.
> 
> 
>          print("Total:", total)
> 
>         print("Current order:", yoda, "at", total)
> 
>     if (order == 2):
> 
> 
> 
> 
> 
> If you've followed my advice:
> 
> 
> if order == "2":
>  
> 
>         movie = eval(input("How many Star Wars Movie DVDs do you want? : "))
> 
>         total = 20 * movie
> 
> 
> As above:
> 
> 
> number_of_movies = int(input("How many Star Wars Movie DVDs do you want? : "))
> 
> total = 20 * number_of_movies 
> 
> 
> 
>         print("Total:", total)
> 
>         print("Current order:", movie, "at", total)
> 
>     if (order == 3):
> 
> 
> 
> 
> 
> If you've followed my advice:
> 
> 
> if order == "3":
>  
> 
>         legos = eval(input("How many Death Star Lego Sets do you want? : "))
> 
>         total = 200 * legos
> 
> 
> 
> As above:
> 
> 
> number_of_legos = int(input("How many Death Star Lego Sets do you want? : "))
> 
> total = 20 * number_of_legos
> 
> 
>          print("Total:", total)
> 
>         print("Current order:", legos, "at", total)
> 
> 
> 
> 
>     shop_again = input("Would you like to keep shopping? 'Y' for yes, 'N' for no: ")
> 
> 
> Again:
> 
> 
> shop_again = input("Would you like to keep shopping? [Y/N]> ").lower()
> 
> 
> 
> shop_again = (shop_again == "y")
>  
> 
>     print()print("Your order before shipping and discounts: ",total)
> 
> print()
> 
> print("Answer a trivia question for a discount!")
> 
> discount = eval(input("On what planet did Yoda live when Luke Skywalker first met him? 1) Earth 2) Dagobah 3) Pluto :"))
> 
> 
> Again:
> 
> 
> discount = input("On what planet did Yoda live when Luke Skywalker first met him? 1) Earth 2) Dagobah 3) Pluto :")
> 
> 
> 
> if (discount == 1):
> 
>     print("Sorry, that answer was wrong!")
> 
> if (discount == 2):    print("That's correct, you get a 10% discount!")
> 
> if (discount == 3):
> 
>     print("Sorry, that answer was wrong!") 
> 
> 
> If you've taken my advice:
> 
> 
>  if discount == "1":
>     print("Sorry, that answer was wrong!")
> 
> 
> if discount == "2":
>     print("That's correct, you get a 10% discount!")
> if discount == "3":
>     print("Sorry, that answer was wrong!") 
> 
> 
>  print()
> 
> if (discount == 2):
> 
> 
> If you've taken my advice:
> 
> 
> 
> if discount == "2":
> 
>  
> 
>     (total * .9)
> 
> 
> Hold on! What do you think this line does? What is it meant to do?
> 
> 
> You meant:
> 
> 
> total = total*.9
> 
> 
> Which for clarity should be written:
> 
> 
> 
> 
> total = total * 0.9
> 
>  
> 
>     print("Your total before shipping: ",total) 
> 
>  print("1) Regular Shipping: 3-4 business days, $5.00 per $50 ordered. 2) Express Shipping: overnight, $10 per $50 ordered. 3) Super Saver Shipping: 7-10 business days, free.")
> 
> shipping = eval(input("Please select the shipping method you want: "))
> 
> 
> 
> 
> Again:
> shipping = input("Please select the shipping method you want: ")
> 
> 
> 
> if (shipping == 1):
> 
> 
> 
> If you've taken my advice:
> 
> <br...
> Show original

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Please help if you can! bobflipperdoodle@gmail.com - 2012-12-26 15:04 -0800
  Re: Please help if you can! Dave Angel <d@davea.name> - 2012-12-26 18:49 -0500
    Re: Please help if you can! bobflipperdoodle@gmail.com - 2012-12-26 16:04 -0800
      Re: Please help if you can! Chris Angelico <rosuav@gmail.com> - 2012-12-27 11:35 +1100
      Re: Please help if you can! Joshua Landau <joshua.landau.ws@gmail.com> - 2012-12-27 00:45 +0000
      Re: Please help if you can! Mitya Sirenef <msirenef@lightbird.net> - 2012-12-26 19:53 -0500
      Re: Please help if you can! Chris Angelico <rosuav@gmail.com> - 2012-12-27 12:00 +1100
        Re: Please help if you can! alex23 <wuwei23@gmail.com> - 2012-12-26 22:33 -0800
      Re: Please help if you can! Mitya Sirenef <msirenef@lightbird.net> - 2012-12-26 20:17 -0500
      Re: Please help if you can! Chris Angelico <rosuav@gmail.com> - 2012-12-27 12:23 +1100
      Re: Please help if you can! Mitya Sirenef <msirenef@lightbird.net> - 2012-12-26 20:42 -0500
      Re: Please help if you can! Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-12-26 21:45 -0500
    Re: Please help if you can! bobflipperdoodle@gmail.com - 2012-12-26 16:04 -0800
  Re: Please help if you can! Joshua Landau <joshua.landau.ws@gmail.com> - 2012-12-26 23:57 +0000
    Re: Please help if you can! bobflipperdoodle@gmail.com - 2012-12-26 16:19 -0800
    Re: Please help if you can! bobflipperdoodle@gmail.com - 2012-12-26 16:19 -0800
  Re: Please help if you can! Dennis <daodennis@gmail.com> - 2012-12-26 17:20 -0800

csiph-web